Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a variable from one Controller Action to another

I would like to pass a variable from one Controller Action to another and display the value on the view script.

class ImportController extends Zend_Controller_Action 
    {
        public function ImportrecordsAction()
        {
            //Do some processing and in this case I select 
            //23 to be the value of total records imported;
            &totalcount = 23;
            //On success go to success page;
            $this->_redirect('/import/success');
        }

        public function SuccessAction()
        {
            //Display the value at the resulting view 
            $this->view->count = &totalcount;
        }

    }

However the &totalcount is returning no value meaning that the variable is not passed to the next action.

How can I solve this?

like image 544
davykiash Avatar asked Jul 29 '26 23:07

davykiash


1 Answers

Instead of a redirect you may want to use a forward. This allows you to forward to another action within your application without doing a complete redirect.

class ImportController extends Zend_Controller_Action 
{
    public function ImportrecordsAction()
    {
        //Do some processing and in this case I select 
        //23 to be the value of total records imported;
        $totalcount = 23;
        //On success go to success page;
        $this->_forward('success','import','default',array('totalcount'=>$totalcount));
    }

    public function SuccessAction()
    {
        $this->view->count = $this->_request->getParam('totalcount',0);
    }

}

Take a look at http://framework.zend.com/manual/en/zend.controller.action.html for more details.

like image 87
Mike Avatar answered Aug 01 '26 17:08

Mike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!