Zend Framework:在引导程序中获取请求对象 [英] Zend Framework: Getting request object in bootstrap

查看:35
本文介绍了Zend Framework:在引导程序中获取请求对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从引导文件中获取请求对象?

How do I get the request object from inside the bootstrap file?

我可以试试这个方法,但是不行.

I can try this methods but not work.

$request= new Zend_Controller_Request_Http();
$request = Zend_Controller_FrontController::getInstance()->getRequest();

推荐答案

如果你真的想,你可以实现这个调用:

If you really want to, you may achieve this calling:

public function _initRequest()
{
    $this->bootstrap('frontController');
    $front = $this->getResource('frontController');
    $front->setRequest(new Zend_Controller_Request_Http());

    $request = $front->getRequest();
}

但是,应该避免这种情况,因为在调度前端控制器(例如模块、控制器或操作名称)之后,您需要的来自 Response 对象的大部分数据都将可用.

However, this should be avoided, because the most data you need from the Response object will be available after the front controller is dispatched (eg. module, controller or action name).

存储在 Response 对象中的其他变量是从全局数组中提取的,例如 $_SERVER$_POST$_GET例外直接在引导程序中读取.

The other variables stored in the Response object are extracted from global arrays such as $_SERVER, $_POST or $_GET which you may exceptionally read directly in bootstrap.

但最有可能的是,您想在前端控制器插件中使用 Response 对象:

But most likely, you want to use Response object in front controller plugin:

class Your_Controller_Plugin_PluginName extends Zend_Controller_Plugin_Abstract
{
     public function preDispatch(Zend_Controller_Request_Abstract $request)
     {
         // do anything with the $request here
     }
}

这篇关于Zend Framework:在引导程序中获取请求对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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