How to get url parameter in Zend Framework?

I am trying to get the parameter passed in the url using the zend framework. But of course this does not work! My code is as follows:

URL creation:

<?php echo $this->url(array('controller' => 'poll', 'action' => 'showresults', 'poll_id' => $poll['_id']), null, true) ?>

Retrieving the poll_id parameter in showresultsAction ():

 $request = new Zend_Controller_Request_Http();
 $poll_id = $request->getParam('poll_id');

The problem is that $ poll_id is NULL. When I do var_dump $ request-> getParams (), it is also NULL. I looked at the Zend Framework document, but it was not very useful. Any ideas? Thank!

+3
source share
2 answers

Instead:

$request = new Zend_Controller_Request_Http();
$poll_id = $request->getParam('poll_id');

Try:

$request = $this->getRequest(); //$this should refer to a controller
$poll_id = $request->getParam('poll_id');

Or:

$poll_id = $this->_getParam('poll_id'); //$this should refer to a controller

Zend Framework automatically attaches the request object to the controller.

+7
source

:

$params = $this->params()->fromQuery();

URL.

+1

Source: https://habr.com/ru/post/1739972/


All Articles