【问题标题】:Zend getParams not returing url paramsZend 获取参数不返回 url 参数
【发布时间】:2016-07-07 18:44:07
【问题描述】:

我有一个问题: https://myaddress.ee/admin/usersearchajax?country=EE&query=arno

$this->_request->getParam('query');
返回:NULL

var_dump($_REQUEST['query']);
返回:string(5) "arno"

如何解决这个问题?我的意思是如何使用 zend 框架获取 GET 值? 假设我无法更改查询字符串。

zend 版本 1.11.11

    public function usersearchajaxAction(){
    $this->_helper->layout()->disableLayout();
    $this->_helper->viewRenderer->setNoRender( true );

    $userService = new Application_Services_User();

    $userList = $userService->searchByName($this->_request->getParam('query'));
    $this->_helper->json($userService->getArrayForAutoComplete($this->_request->getParam('query'), $userList));

}

我发现了问题,我的项目中有 $_GET 变量并被覆盖。 所以现在修复了。感谢大家阅读和思考这个问题

【问题讨论】:

标签: ajax zend-framework


【解决方案1】:

而不是

$this->_request->getParam('query');

使用这个

$this->_getParam('query');

不需要在 Action 中使用 request action helper 来获取这个参数

或尝试使用这种使用请求操作助手的方式

$request  = $this->getRequest();
$query = $request->getParam('query');

希望link 对您有所帮助

【讨论】:

  • 使用$this->_request->getParam()没有任何问题。您提到的第二种形式是代理第一种形式的语法糖。同样,在幕后,获取对请求操作助手的引用并调用getParam 方法与$this->_request->getParam() 完全相同。
【解决方案2】:

您还可以连续查看所有参数$this->_request->getParams(); 然后连续找到needle param并get using$this->_request->getParam('needle');

【讨论】:

  • getAllParams 方法应该是getParams。我无法编辑更改,因为编辑需要超过 6 个字符。
猜你喜欢
  • 2012-11-03
  • 2013-10-07
  • 1970-01-01
  • 2011-09-06
  • 1970-01-01
  • 2015-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多