[Solved] Configure Module Components

Eeverything works fine, when i'm using main configuration file of application for customizing module components.

But i want to make module with default settings.

I tried to configure components inside DownloadModule which extends CWebModule:



<?php


	public function init()


	{


		// this method is called when the module is being created


		// you may place code here to customize the module or the application





		// import the module-level models and components


		$this->setImport(array(


			'download.models.*',


                        'download.components.*',


		));





                    $this->configure(array(


                         'preload'=>'log',


                        'components'=>


                         array(


                                'log'=>array(


                                    'class'=>'CLogRouter',


                                    'routes'=>array(


                                        array(


                                            'class'=>'CFileLogRoute',


                                            'levels'=>'trace, info',


                                            'categories'=>'download',


                                            'logFile'=>'report'


                                        ),


                                    )


                            )


                        )));


                


	}


?>


Controller:



<?php


class DefaultController extends CController


{


	public function actionIndex()


	{


            Yii::log("hello",'info','download');


            $this->render('index');


	}


}


?>


But module keeps using components settings from main configuration file of application.

In you main config.php, did you add this to the componets

        ,'yourModule' => array(

            'class'=>'application.components.yourModule',

Quote

In you main config.php, did you add this to the componets

        ,'yourModule' => array(

            'class'=>'application.components.yourModule',

I think your mean  'class'=>'application.modules.yourModule',

Anyway, i tried all variants, and nothing helps. Also, i can't understand why should i use the code that u wrote. There is nothing in documentation and cookbook about this.

Quote

A module can also be congured with initial property values. The usage is very similar

to conguring application components.

From application components:

Quote

By conguring the components property of application, we can customize the class and

property values of any application component used in an application. For example, we

can congure CMemCache component so that it can use multiple memcache servers for

caching,

array(

'components'=>array(

'cache'=>array(

'class'=>'CMemCache',

'servers'=>array(

array('host'=>'server1', 'port'=>11211, 'weight'=>60),

array('host'=>'server2', 'port'=>11211, 'weight'=>40),

),

),

),

)

'class' array element is required because of an algorythm used in YII to instantiate components and modules. Class name is never split from property values. Otherwise instrantiation wouldn't be solid.

Quote

'class' array element is required because of an algorythm used in YII to instantiate components and modules. Class name is never split from property values. Otherwise instrantiation wouldn't be solid.

You misunderstood me. I'm talking about configuring modules. (http://www.yiiframework.com/doc/guide/basics.module)

I'm not sure that 'class' prroperty is applicable for module, just for his components.



<?php


        'modules'=>array('download'=>


         array(


            'preload'=>array('log'),


            'components'=> array(


                'log'=>array(


                    'class'=>'CLogRouter',


                    'routes'=>array(


                        array(


                            'class'=>'CFileLogRoute',


                            'levels'=>'trace, info',


                            'categories'=>'download',


                            'logFile'=>'report'


                        ),


                    )


                 )


            )


        )


?>


Also i assume, that  you shouldn’t use property ‘class’ in modules as foe#1 wrote,  if you keep Yii’s  conventions.

I found the solution.



<?php


class DownloadModule extends CWebModule


{


	public function init()


	{


		$this->setImport(array(


			'download.models.*',


                        'download.components.*',


		));





                $this->configure(array(


                    'preload'=>array('log'),


                    'components'=>array(


                        'log'=>array(


                            'class'=>'CLogRouter',


                            'routes'=>array(


                                 array(


                                    'class'=>'CFileLogRoute',


                                    'levels'=>'trace, info',


                                    'categories'=>'download',


                                    'logFile'=>date("d.m.y").".log",


                                 ),


                            ),


                         ),


                    )


                ));





                $this->preloadComponents();


	}


}


?>