1

How can I call a module in another module? This code works on my Controllers in Protected/Controllers:

$image = Yii::app()->image->save($photofile, 'some_name','uploadedGal');

But in the controller of my other module (admin) I get this error.

Property "CWebApplication.image" is not defined. 

I have defined the image module in my main config file:

'modules'=>array(
           'image'=>array(
                    'createOnDemand'=>true, // requires apache mod_rewrite enabled
                    'install'=>true, // allows you to run the installer
            ),
            'admin',

),
2
  • Maybe what you want is to define a custom CComponent. Commented Jun 15, 2012 at 15:31
  • No, I have my backend as a module admin and in the backend I need to use a module for image management image. I followed all the instructions and it works in the frontend, but it doesnot work in the backend which is a module itself Commented Jun 15, 2012 at 15:39

2 Answers 2

7

You need to include the other module components in your module class. Something like this:

class AdminModule extends CWebModule
{
    public function init()
    {
        $this->setImport(array(
            'admin.models.*',
            'admin.components.*',
            'image.models.*',
            'image.components.*',
        ));
}
Sign up to request clarification or add additional context in comments.

2 Comments

Also, I found that I could add this: Yii::app()->setComponents(array('image'=>array('class'=>'application.modules.image.components.ImgManager'))); before using the other module...
@MahsaTeimourikia nice!! but it would be a little hard to maintain :P
2

You can import the module components in the config/main.php like below:

'import'=>array(
    'application.models.*',
    'application.components.*',
    'application.modules.admin.models.*',
        'application.modules.admin.components.*',
            ....
            ....
),

This way all models etc will be imported for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.