问题
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