Zend 框架的 getRequest()->getQuery() 不会在本地主机上带来查询字符串 [英] Zend framework's getRequest()->getQuery() won't bring query string on localhost

查看:49
本文介绍了Zend 框架的 getRequest()->getQuery() 不会在本地主机上带来查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,它在实时站点上运行良好,但在 localhost 上不起作用.

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

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

我有一个这样的网址:

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

我打印了 status 的值,该值始终为零.我是 Zend 框架的新手,在网上找不到解决方案,对我来说看起来很奇怪.有什么想法吗?谢谢.

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.

[已修复]

我有错误的 RewriteRule 导致了这个问题.有一个不需要的?"在 RewriteRule 行中的 index.php 之后.我添加了这个是我的错误,因为其他框架如 CodeIgniter 用户 '?'在重写规则中.更正后的 RewriteRule 行是:

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.. :-)

推荐答案

我通常用这个

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

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

我假设您有一个问题控制器询问操作.
这是有关 Zend 请求的文档

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

这篇关于Zend 框架的 getRequest()->getQuery() 不会在本地主机上带来查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆