2010-04-12 71 views

回答

0

您需要首先引导FrontController设计,你可以试试:

function initFoo() 
{ 
    $this->bootstrap('frontController'); 
    $req = $this->frontController->getRequest(); 
} 
+0

没有工作!返回:“致命错误:调用成员函数getParam()” – 2010-04-12 17:24:49

+0

我认为第二行应该是'$ this-> getResource('frontController')' – chelmertz 2010-04-12 18:07:31

+0

此外,这不是_initFoo()? – jackyalcine 2012-06-19 19:57:29

10

你不应该获得请求OBJET,因为如果你看到派遣循环,这个想法是,自举是在请求中执行之前的动作。

如果您需要改变应用程序的某个部分,请使用Controller Plugin来完成此操作。

12

如果你真的想,你可以做到这一点呼叫:

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

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

然而,这应该是可以避免的,因为你从Response对象最需要的数据将提供前端控制器被派遣后(例如模块,控制器或动作名称)。

存储在响应对象中的其它变量从全局数组如$_SERVER$_POST$_GET您可能分外直接在自举读萃取。

但最有可能的,你要使用Response对象在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 
    } 
} 
+0

preDispatch是执行此操作的正确方法。 – Dharmang 2015-08-03 05:39:11

-4

使用工厂而不是

http://www.yourweb.com/somecontroller/index/id/12

的$ id =在Zend_Controller_Front ::的getInstance() - >调用getRequest( ) - > ID;

echo $ id;

// echo 12

+0

这肯定不会工作,因为前端控制器在引导时尚未分派,因此请求参数不可用 – 2011-08-10 06:00:27

+3

-1请求对象在该点不可用。 – JohnP 2011-08-10 06:01:52

相关问题