Custom Module Path

Hi,

There is a module in my Yii based aplication which resides in default modules path (protected/application/modules). I need to move this module to common path for multiple projects (/var/www/yiimodules) while rest of modules remain in default modules path.

There are many references to this module in application. For example:

application.modules.ContentManagement.views.layout.default (in base controller)

application.modules.ContentManagement.controllers.* (in config)

I need to change load path from protected/application/modules/ContentManagement to /var/www/yiimodules/ContentManagement while retaining application.modules.ContentManagement references.

Is it possible?

I don’t know if that’s possible but why not refactoring it all and updating those references to the module files?

What you could do is to put several rows into main.php ‘import’ attribute of the webapp configuration like [size=“2”][color="#1C2837"]‘application.yiimodules.ContentManagement.controllers.*’ and then in the application itself refer to the referred files directly without the need to fully qualify them. That will require a single search-and-replace throughout the app that is relatively simple (and if you’re careful not to forget anything also relatively safe regarding bugs).[/color][/size]

Thanks for replying.

I’ve added this at the top of config/main.php:


Yii::setPathOfAlias('customModules', '/var/www/yiimodules');

and this is a code for including modules, also in config/main.php:


$config = array(

	...

	'modules'=>array(

		...

		'ContentManagement' => array (

			'class' => 'customModules.ContentManagement.ContentManagementModule'

		)

                ...

	),

...

After this change URLs that target controllers in module don’t work anymore. For example:

www.example.com/ContentManagement/admin

Error message is:


Alias "ContentManagement.ContentManagementModule" is invalid. Make sure it points to an existing PHP file

Seems that application implicitly tries to load module from ContentManagement.ContentManagementModule when calling controllers inside module.

I agree with Boaz.

You can also try setting a path alias to the shared directory:




Yii::app()->setPathOfAlias('sharedModules', '/var/www/yiimodules');



I’m sorry, the page was open for a while and I didn’t see your reply.

I believe that the best alternative is to use CWebApplication::controllerMap.

Ok. Thanks!

I am going to try ControllerMap solution.