我正在尝试使用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-&gt; getParams()的var_dump时,它也是NULL。我已经浏览了Zend Framework文档,但它并不是很有用。任何的想法 ?谢谢!
答案 0 :(得分: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 Framework自动将请求对象附加到控制器。
答案 1 :(得分:1)
尝试从控制器中获取此信息:
$params = $this->params()->fromQuery();
返回所有网址参数。