Zend framework's getRequest()->getQuery() won't bring query string on localhost

十年热恋 提交于 2019-12-30 06:47:48

问题


I have the following code, which works fine on live site, but not on localhost.

$status = $this->getRequest()->getQuery('status');

I have a URL like this:

http://localhost:888//questions/ask?status=10

I printed the value of status, which is always nil. I am new to Zend framework and could not find a solution to this on net, looks strange to me. Any thoughts? Thanks.

[FIXED]

I had wrong RewriteRule that caused the problem. There was an unwanted '?' after index.php in RewriteRule line. It was my mistake I added this, because other frameworks like CodeIgniter user '?' in RewriteRules. The corrected RewriteRule line is:

RewriteRule ^(.*)$ /index.php/$1 [L]

I wonder if I can choose this as accepted answer.. :-)


回答1:


I usually use this

$status = $this->getRequest()->getParam('status');

// or
$status = $this->getRequest()->getParams();

I assume that you have a Questions Controller Ask Action.
Here is the documentation about Zend's request




回答2:


For those looking for the solution to ZF2 - look at this post, helped me out dramatically. It even includes the reference to a phenomenal plugin to make this easier (as the very least, in understanding the routes/requests/params, etc...)

Getting $_GET parameters from route in Zend Framework 2

Also, in this post SO post

How to access route, post, get etc. parameters in Zend Framework 2

In short, tho -

    $this->getRequest()->getRequest('name', 'default');
    $this->getEvent()->getRouteMatch()->getParam('name', 'default');


来源:https://stackoverflow.com/questions/3733454/zend-frameworks-getrequest-getquery-wont-bring-query-string-on-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!