CakePHP 3.x:如何扩展请求类

问题描述:

我有一个插件,我希望扩展Request类(Cake\Network\Request),以添加可供我的插件的控制器使用的新方法和属性。CakePHP 3.x:如何扩展请求类

怎么办? 谢谢。

创建您的扩展要求,并简单的通过它的一个实例给调度员在自己的应用webroot/index.php前端控制器:

https://github.com/cakephp/app/blob/3.0.0/webroot/index.php#L35

// .... 

use App\Network\MyCustomRequest; 

$dispatcher = DispatcherFactory::create(); 
$dispatcher->dispatch(
    MyCustomRequest::createFromGlobals(), // there it goes 
    new Response() 
); 
+0

感谢@ndm,它的工作原理。 – 2015-04-03 09:39:06