Using controller in several modules

Hi!

Wonder if I can use a controller in several modules… This is the point, I have a controller which has an actionCreate, but I need to implement the action (create) in two different modules (with differents layouts, by the way).

I am not sure about this since I am a Noobie, but I have been experimenting with inheriting models and am not sure why you couldn’t do the same with Controllers.

I have used this thread to get me started … let me know if this helps.

Thks pal, actually I’m also new, I was thinking of this before… the point is that as I have two different modules (each one with its own layout), I extend every controller inside the modules from a BaseController in which I’ve defined a main layout for the module, so, my modules controllers can not extends from another class but the BaseController for the especific model…

I’ll take a look at your link…

Thanks again…

If all of your controllers are inherited from a single Base class, can’t you have your actionCreate() method as part of that class and keep it or overwrite it as you see fit in the child classes?

Maybe I am missing something.

Ok… this is how I got it:




/** This is application level Controller **/

class PrincipalController extends Controller {

    /** code **/

    public function actionCreate() {

         $model = new Model;

         //some code ...

    }

    /** code **/

}






/** This is module1 level Controllers **/

class Module1BaseController extends Controller {

    //some other variables

    public $layout = 'application.modules.modules1.views.layouts.main';

}


class ContentController extends Module1BaseController {

    public function actionCreate() { 

        //this action create, I need the same behavoir as actionCreate in PrincipalController (application level)

    }

}






/** This is module2 level Controllers **/

class Module2BaseController extends Controller {

    //some other variables

    public $layout = 'application.modules.modules2.views.layouts.main';

}


class ContentController extends Module2BaseController {

    public function actionCreate() { 

        //this action create, I need the same behavoir as actionCreate in PrincipalController (application level)

    }

}