Module and loading module extensions

I use extension in my module.

When i write in the module init() function:


$this->setComponents(array(

    'some_extension' => array(...),

));

  • it doesn’t work.

But when i put this code in the main.php config:


'components'=>array(

...

		'some_extension' => array(...),

...

  • all works fine.

How i can register extension component into my module ? (and make preload too)

Thank you

Anybody knows ?

For example i use extension only in the backend/admin part, so don’t need to load this on the application start…

In your main I think it should be something like:


'modules' => array(

  'yourmodule' => array(

     'components' => array(

       'yourextension => array()...

     ), 

  ),

)

Try Yii::app()->setComponents().

I’am using it for components setting of my module like this:




// Load AdminModule config

$moduleConfig = require('config'.DIRECTORY_SEPARATOR.'main.php');

// Override/Merge/Create application components settings

Yii::app()->setComponents($moduleConfig['components']);



Thanks very much HermesCK and others – I was having the same problam and the suggestion to call Yii::app()->setComponents from the module init, instead of $this->setComponents solved it.

it’s not 100% correct.

i suggest to define components in main.php




'modules'=>array(

    'www'=>array(

        'class'=>'applications.modules.www.WwwModule',

        'components' => array(

             'api'=>array('class'=>'www.components.ApiBase'),

             'curl'=>array('class'=>'www.vendors.Curl'),

        ),

    ),

),




and then:




$api = $this->getModule()->api;

$curl = $this->getModule()->curl;



"$this" is current controller.

one more thing:

‘api’=>array(‘class’=>‘www.components.ApiBase’),

"www" is path alias here, and it will be created automatically when you setup module