简体   繁体   中英

can i use getRequest() in clicommands of zend framework

I'm using zendframework. Here i used getRequest() method outside the controller, inside the CliCommands class.But it through an error.

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

Is there any way to use the getRequest() outside the controller?

UPDATE:

After using this:

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

Now I'm getting this type of error:

Fatal error: Uncaught Error: Call to a member function getParams() on null

From inside the controller you can use any one of these

$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');

Or from outside the controller (and after the front controller is loaded):

$front = Zend_Controller_Front::getInstance();
$all = $front->getRequest()->getParams();
$one = $front->getRequest()->getParam('key');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM