开发者

How to retrieve an url parameter in the Zend Framework?

开发者 https://www.devze.com 2022-12-26 00:31 出处:网络
I\'am trying to retrieve an parameter pas开发者_StackOverflowsed in a url using the zend framework. But of course, it is not working !

I'am trying to retrieve an parameter pas开发者_StackOverflowsed in a url using the zend framework. But of course, it is not working ! My code looks like this :

Generating the url :

<?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 a var_dump of $request->getParams(), it is also NULL. I have glanced trough the Zend Framework doc, but it was not very usefull. Any idea ? Thanks !


Instead of:

$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

The Zend Framework automagically attaches the request object to a controller.


Try to involve this from the controller:

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

It returns all URL parameters.

0

精彩评论

暂无评论...
验证码 换一张
取 消