Can*_*ğan 12 php bootstrapping zend-framework request
如何从引导程序文件中获取请求对象?
我可以尝试这种方法但不起作用.
$request= new Zend_Controller_Request_Http();
$request = Zend_Controller_FrontController::getInstance()->getRequest();
Run Code Online (Sandbox Code Playgroud)
tak*_*hin 12
如果你真的想,你可以实现这个要求:
public function _initRequest()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$front->setRequest(new Zend_Controller_Request_Http());
$request = $front->getRequest();
}
Run Code Online (Sandbox Code Playgroud)
但是,应该避免这种情况,因为在调度前端控制器之后,您需要从Response对象获得的大多数数据都可用(例如,模块,控制器或操作名称).
存储在响应对象中的其它变量都从全局数组如提取$_SERVER,$_POST或者$_GET您可以格外在自举直接读取.
但最有可能的是,您希望在前端控制器插件中使用Response对象:
class Your_Controller_Plugin_PluginName extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
// do anything with the $request here
}
}
Run Code Online (Sandbox Code Playgroud)
您需要首先引导 frontController,尝试以下操作:
function initFoo()
{
$this->bootstrap('frontController');
$req = $this->frontController->getRequest();
}
Run Code Online (Sandbox Code Playgroud)