Application Controller exends a Module Controller

Hi,

I’d like know how a application controller (like SiteController) can exteds a Module controller?

I’m creating a module with a controller that need to be extended for all applications controllers.

Thanks.

I did this. I created a subclass of CModule and CController to work together.

Its not packaged up but you can browse my source code @ google: http://code.google.com/p/ps-yii-extensions

Hi guy, I’m looking your code but I think that is not what I want.

Look my idea:

I have a module called "generic" with one controller called GenericController.




class GenericController extends CController {}



On my root application I have a controller called "SiteController" that extends "GenericController" of model




class SiteController extends model.generic.GenericController {}



I’d like know if can I make this (or any thing like it) on Yii?

Thanks.

You need to import the module or it’s controllers before creating a child of it.

you can do this


Yii::app()->getModule('generic');

class SiteController extends GenericController...

or you could add the generic module to the import array in your protected/config/main.php like


	'import'=>array(

....................................

		'application.modules.generic.controllers.*',

...................................

or you could just do a require/include on the file GenericController.php where i put Yii::app()->getModule(… in the first example.

Hi jayrulez, I understood, but I intend to create this controller on a module becouse besides the generic controller I intend to create a default views (css | html | js), and use this views in all controllers that extend the generic controller.

Based on your exemples I think that the best form is importing on array in protected/config/main.php, but I don’t know if the generic view will work on this form.

Do you know if the views will work that form?

Thanks.

Hi jayrulez,

I did your sugestion, and I managed to extend the controller of generic module on all controller of root application, but the generic view of module not work.

To fix up this problem I changed the module controller to extend CExtController instead of extend CCcontroller, and now the application can’t found the index view, and it’s throwing a exception: SiteController cannot find the requested view “index”.

How can I fix up this?

Thanks.

Hi guys,

I finally got fix up the views problem, the solution is very simple, I just needed to changed the path of view to "generic.views.default.index" instead of put only "index".

I found this reading this post http://www.yiiframework.com/forum/index.php?/topic/4542-using-application-layout-inside-a-module/page__st__-20__p__18__hl__viewPath__fromsearch__1&#entry18

Now I’ll start a new phase of my module.

This post is resolved.

Thanks for All