我可以在zend框架的cli命令中使用get Request()

问题描述 投票:0回答:1

我正在使用zendframework。这里我在控制器外部使用了getRequest()方法,在CliCommands类中。但是它通过了一个错误。

 PHP Fatal error:  Uncaught Error: Call to undefined method
 V1Command::getRequest().

有没有办法在控制器外部使用getRequest()?

更新:

使用后:

$front = Zend_Controller_Front::getInstance();
$all = $front->getRequest()->getParams();

现在我遇到了这种类型的错误:

致命错误:未捕获错误:在null上调用成员函数getParams()

php zend-framework2 icinga2
1个回答
0
投票

从控制器内部,您可以使用其中任何一个

$all = $this->getRequest()->getParams();
$one = $this->getRequest()->getParam('key');

$all = $this->_request->getParams();
$one = $this->_request->getParam('key');

$all = $this->_getAllParams();
$one = $this->_getParam('key');

或者从控制器外部(以及加载前控制器后):

$front = Zend_Controller_Front::getInstance();
$all = $front->getRequest()->getParams();
$one = $front->getRequest()->getParam('key');
© www.soinside.com 2019 - 2024. All rights reserved.