[ACCEPTED]-Zend: Redirect to Action with parameters-redirect

Accepted answer
Score: 50

you can try with redirector:

$params = array('user' => $user, 'mail' => $mail);
$this->_helper->redirector($action, $controller, $module, $params);


Score: 30

Use the Zend_Controller_Action::redirect() method (which just passes through 6 to Sarfraz's helper method)


Note: _redirect() method 5 is deprecated as of Zend Framework 1.7. Use 4 redirect() instead.

And then in the called action:

$username = $this->_getParam('username');
$email = $this->_getParam('email');

_getParam() takes 3 a second optional argument which is set 2 to the variable as a default if the parameter 1 isn't found.

Score: 7

You may want to try this:



Score: 4

You can also add $params say like for userid

public function indexAction ()
    $auth = Zend_Auth::getInstance();
    if ($auth->hasIdentity()) {
        // Identity exists; get it
        $identity = $auth->getIdentity();
        $this->_redirect('/user/profile/' . $identity->user_id);
    } else {

I 5 forgot to mention, of course this is assuming 4 you have the routing setup to accept a $param. As 3 an example the routing would look something 2 like this for the page that is being redirected 1 to in the example above:


resources.router.routes.user-profile.route = /user/profile/:id
resources.router.routes.user-profile.defaults.module = default
resources.router.routes.user-profile.defaults.controller = user
resources.router.routes.user-profile.defaults.action = profile

Score: 1

How you get the param sorta depends on where 20 you are,

You do not have to catch a request 19 $param to achieve what you want to do here. You 18 are just using the FlashMessenger helper 17 to add a message to the stack. You then 16 retrieve the message within the action where 15 you want to show the message, then assign 14 it to the view as I do in the successAction. Keep 13 in mind that you can pass any $var or array 12 of data by assigning it in the controller 11 like: $this->view->var = $var; Within the 10 view that will then be accessed as $this->var.

Since 9 you asked about login I will show you how 8 I usually do it. Not that its the best way.

My 7 LoginController's index view holds the form:

    public function indexAction() {
    $form = new Zfcms_Form_Login;
    $this->view->form = $form;
     /*check for valid input
       authenticate using adapter
       persist user record to session
       redirect to original request URL if present*/
    if ($this->getRequest()->isPost()) {
        if ($form->isValid($this->getRequest()->getPost())) {
            $values = $form->getValues();

            $authAdapter = $this->getAuthAdapter();

            # get the username and password from the form
            $username = $values['username'];
            $password = $values['password'];

            # pass to the adapter the submitted username and password

            $auth = Zend_Auth::getInstance();
            $result = $auth->authenticate($authAdapter);

            if ($result->isValid()) {

                # all info about this user from the login table
                # ommit only the password, we don't need that
                $userInfo = $authAdapter->getResultRowObject(null, 'password');

                # the default storage is a session with namespace Zend_Auth
                $authStorage = $auth->getStorage();

                $session = new Zend_Session_Namespace('zfcms.auth');
                if (isset($session->requestURL)) {
                    $url = $session->requestURL;
                } else {
                            ->addMessage('You were successfully logged in as ' . $userInfo->username);
            } else {
                $this->view->message = 'You could not be logged in. Please try again.';

In 6 the success action we do this:

public function successAction() {
    if ($this->_helper->getHelper('FlashMessenger')->getMessages()) {
        $this->view->messages = $this->_helper
    } else {

In the view 5 script we can do something like what I have 4 below. The reason I do it this way is that 3 sometimes I will pass only a single message 2 in a controller, in this case I simply use:

$this->view->message = 'message goes here';

Then 1 catch them both if they are set in the view:

    if(isset($this->message) || isset($this->messages)):

    echo implode($this->messages);
} else {
    echo $this->message;


More Related questions