3

我正在尝试使用 zend 框架检索在 url 中传递的参数。但是,当然,它不起作用!我的代码如下所示:

生成网址:

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

在 showresultsAction() 中检索“poll_id”参数:

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

问题是 $poll_id 为 NULL。当我执行 $request->getParams() 的 var_dump 时,它也是 NULL。我浏览了 Zend Framework 文档,但它不是很有用。任何的想法 ?谢谢 !

4

2 回答 2

7

代替:

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

尝试:

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

或者:

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

Zend 框架自动将请求对象附加到控制器。

于 2010-04-06T10:11:22.877 回答
1

尝试从控制器中涉及到这个:

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

它返回所有 URL 参数。

于 2016-07-26T06:51:55.470 回答