-- debussy007 <[EMAIL PROTECTED]> wrote
(on Thursday, 20 September 2007, 12:56 PM -0700):
> I wondered how to pass info between two controllers. 
> Here is the case explained where I need it :
> 
> I have an AuthController which is responsible for all login/logout actions.
> 
> When I notice someone put a bad username and/or password, 
> the AuthController forwards the flow to the IndexController which will
> render the home page 
> and I want to display a message to explain it is a bad user and/or password
> on this home page.
> 
> So the question is how do I specify that there was a bad connection attempt 
> between the AuthController and the IndexController ?
> 
> In other words how do I transfer the information between the AuthController
> and the IndexController 
> that the connection failed ? What is the best way ?

The fourth parameter to _forward() is an array of paramater values to
set in the request object:

    $this->_forward('index', 'index', null, array('error' => 'Bad login 
credentials'));

You'd then retrieve this in the other controller using _getParam():

    $error = $this->_getParam('error', false);
    if ($error) {
        // assign error to view?
    }

Alternatively, you could simply set a view variable, and check for that
in the home page view script:

    $this->view->error = 'Bad login credentials';

Finally, you could use the FlashMessenger helper (as Darby has already
noted); this helper is best used for passing messages to subsequent
requests.

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to