Importing controllers,views and models in module

I have a module which has its own controller and models and would like to import the controllers, views and models of the protected folder i.e. protected/controllers , protected/views , protected/model.

I want to use the functionality of my module along with the ones in protected.

What will be the procedure for implementing this?

In your module file, let’s say MyOwnModule.php (that means your module is named eg MyOwn) override CModule.init() method:




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(

		'myOwn.models.*',

		'myOwn.components.*',

	));

}



This code is generated by Gii.

And all code in your application (that is from protected directory) is automatically available to your module.

Of course if your import it in config/main.php:




    'import' => array(

        'application.models.*',

        'application.components.*',

    ),



When you want to access application model, let’s say User your path alias is:




'application.models.User'



When you want to access module model, let’s say Organization your path alias is:




'myOwn.models.Organization'



Read more about modules here: http://www.yiiframework.com/doc/guide/1.1/en/basics.module