Nice, this works great  :-)  !!

I have also thought about setting up plugins and helpers. But I think it is
a regret that helpers and plugins doesn't work per module.
E.g. In my case, I have a module default (for guests and members), partners
and admin. And if authentication fails, I have to forward to the correct
login page (they have all their login page), and secondly in default module
you can access as a guest, so no need for authorization and authentication.
So those two points involves already a switch condition statement. Then for
the default module I set some variables when user is logged, which is not
the case for the other modules.
etcetera etcetera
That's why I choosed to extend the Zend_Controller_Action class, because I
can create one parent class per module which gives me more flexibility.



Matthew Weier O'Phinney-3 wrote:
> 
> -- debussy007 <[EMAIL PROTECTED]> wrote
> (on Saturday, 29 September 2007, 12:58 PM -0700):
>> 
>> Hello all !
>> 
>> I have a problem with the preDispatch method : 
>> 
>> To check for authentication and authorization I created my own parent
>> class
>> for all controllers (and for other common code). 
>> And this parent class extends Zend_Controller_Action.
>> 
>> I call in each controller the method preDispatch of the parent class I
>> created.
>> 
>>      function preDispatch() {
>>              parent::preDispatch();
>>              echo 'other instructions here';
>>      }
>> 
>> When the parent finds bad auth or acl rights, it forwards to the login
>> page.
>> 
>> The problem is that the instructions in the controllor below the parent
>> call
>> are still executed.
>> E.G. in my code above the "other instructions here" string is displayed
>> on
>> the screen.
> 
> That makes sense. A _forward() action merely sets state in the request
> object; it doesn't halt or modify execution flow (it can't, really).
> What you'll want to do is check that status after parent::preDispatch()
> has finished running, and then act on it:
> 
>     function preDispatch() 
>     {
>         parent::preDispatch();
>         if (!$this->getRequest()->isDispatched()) {
>             return;
>         }
> 
>         echo 'other instructions here';
>     }
> 
> BTW, it may make more sense to move such checks into an action helper
> instead of creating a base class for your controllers; that way you can
> use that functionality (ACL checks, etc) in other applications without
> needing to use that base class.
> 
> 
> -- 
> Matthew Weier O'Phinney
> PHP Developer            | [EMAIL PROTECTED]
> Zend - The PHP Company   | http://www.zend.com/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/question-about-preDispatch-tf4540709s16154.html#a12975319
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to