-- 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/

Reply via email to