CakePHP 3.x: how to extend the Request class

杀马特。学长 韩版系。学妹 提交于 2020-01-06 15:14:34

问题


I have a plugin and I wish to extend the Request class (Cake\Network\Request), to add new methods and properties that can be used by the controllers of my plugin.

How to do? Thanks.


回答1:


Create your extended request class and simply pass an instance of it to the dispatcher in your apps webroot/index.php front controller:

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()
);


来源:https://stackoverflow.com/questions/29408489/cakephp-3-x-how-to-extend-the-request-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!