views:

31

answers:

2

Hi,

I was thinking about extending all my controllers from the indexController. I have in the index controller a init() function that does alot of stuff. This is not executed upon fooController request.

I allready have a registered a viewSetup plugin. And this is executed on all requests and thats just fine.

My problem is a have blog module which needs to do some stuff, that don't need to be done in the news module.

A good example is my secondary menu, its specific to the active module.

class fooController extends indexController In this way i could also override the init() function in indexController from within fooController. Unfortunately the autoloader can't find the indexController class.

The following works though, if i require the indexController.php file first

<?php
require_once('indexController.php);

class fooController extends indexController {

    function init() {
        parent::init();

        // Do changes to, ie. setup controller specific menu, or add menu items.
    }
}

Ideas much appreciated :)

+1  A: 

This seems to be a case for an action helper. You can package the common functionality into such a helper and invoke it on a per-controller basis (in the init() method) or an a per-action basis.

David Weinraub
A: 

Possible solutions, depends what do you want to do:

  • custom Abstract controller class
  • bootstrap _init method
  • action helper
  • overloading methods
  • controller plugin

Looks like the controller plugin is the best in this case (since you are already using one), but you just need to add some conditions to it, e.g. execute the code only when specific module, controller and action are requested.

takeshin
I think you're right. The most modular solution would probably be to setup special conditions ind the viewSetup or actionSetup plugin that i allready have utilized.
Phliplip