You can also do this without a base action controller. Action helpers have
their own preDispatch and postDispatch hooks, so as long as you register the
action helper early (like in your bootstrap), it will run on every request.
The nice thing about action helpers is that they have access to the current
action controller ($this->getActionController()) so if you need to set any
new (public) properties on it you can.
You can register an action helper simply by asking the action helper broker
to retrieve it:
$myHelper =
Zend_Controller_Action_HelperBroker::getStaticHelper('MyHelper');
--
Hector
On Sun, Jan 24, 2010 at 3:32 PM, iSac <[email protected]> wrote:
>
> I'm not sure what you mean by super controller, so I'll describe the ways
> I'd
> think to do it. In advance, to save time if need be, I recommend 1.
>
> 1) In your library, which is on your include path, have a folder MyApp,
> which contains ZF extensions and other classes that are specific to your
> app. The base controller class would be MyApp_Controller_Action. I think
> this is the other (non-super controller) solution you were referring to.
>
> 2) In your library, have a folder MyDeveloperTagName, which contains ZF
> extensions and other classes that you use in your projects in general. For
> instance, if you think that this bit of functionality is something you'd
> want to use in all of your ZF applications, not just the one you're
> currently working on (or at least the one that inspired this post), do
> this.
> The base controller class would be MyDeveloperTagName_Controller_Action.
>
> 3) In your controllers folder inside your application folder (the one that
> has your views and models) make a base class MyAppController, from which
> all
> others extend.
>
> Between these I'd recommend 1 or 2. 3 can get a little annoying if you want
> to start having different modules, and I don't think it has anything over 1
> or 2. Also, from a design perspective, your "client-facing controllers"
> should only have to worry about their own little world, nothing global
> (full
> disclaimer that that's just, like, my opinion,... man).
>
> As far as whether 1 or 2, starting with 1 is probably the best. 2 is good
> if
> you know you want the functionality replicated across multiple projects,
> but
> isn't really necessary to start, and it can be good to make these decisions
> locally (ie local to a specific project) to start anyway.
>
> If you do choose 2, create a MyApp_Controller_Action base controller class
> that extends MyDeveloperTagName_Controller_Action anyway, so that you can
> make app specific changes there.
> --
> View this message in context:
> http://n4.nabble.com/Same-predispatch-in-every-controller-Where-s-a-better-place-to-put-it-tp1288632p1288932.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>