Pravin Prasad
Pravin Prasad

Reputation: 223

Zend - Sending value in request object and accessing it on controller or View

I want to redirect to a page from a controller in zend. Before redirection I want to set some values in the request object and then I want to get these values on the controller where I have redirected.

I can do it by query string but I dont want to send these values in URL.

Please let me know:

  1. How can I set these values in request object in zend.
  2. How can I get these values after redirection.
  3. Which method should I use for redirection.

The main aim is to avoid using query sting. Let me know the solution.

Thanks in advance.

Pravin

Upvotes: 1

Views: 265

Answers (3)

coolguy
coolguy

Reputation: 7954

You can use Zend Flashmessenger although it is used for showing messages..you can do it for this also

Assuming you get ur post values in FooController/barAction

public function barAction(){
$flashMessenger = $this->_helper->getHelper('FlashMessenger');
$val1 = $this->_request->getPost('val1');
$val2 = $this->_request->getPost('val2');
$flashMessenger->addMessage(array('val1' => $val1 ,'val2' => $val2));
$this->_redirect('somecontroller/someaction'); 
}

Then in someaction,

public function someAction(){
$flashMessenger = $this->_helper->getHelper('FlashMessenger');
$this->view->flashmsgs = $flashMessenger->getMessages();   //This will get you the array  
}

Upvotes: 0

max4ever
max4ever

Reputation: 12142

Have you tried using this before redirect

$something = new Zend_Session_Namespace('abc');
$something->other = 123;

and then extract the data with

$something = new Zend_Session_Namespace('abc');
if (isset($something->other))
{
    $my_var = $something->other;//that is 123
}

Upvotes: 2

Taras Taday
Taras Taday

Reputation: 131

If session is not acceptable then I can see two ways:

  1. use _forward method and execute new action in scope of current request http://framework.zend.com/manual/en/zend.controller.action.html#zend.controller.action.utilmethods

  2. use empty page that contains form with hidden elements that will be automatically submitted by javascript

Upvotes: 3

Related Questions