CakePHP 3.x:如何扩展Request类 [英] CakePHP 3.x: how to extend the Request class

查看:176
本文介绍了CakePHP 3.x:如何扩展Request类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个插件,我想扩展请求类( Cake\Network\Request ) ,添加可以由我的插件的控制器使用的新方法和属性。

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.

推荐答案

创建扩展请求类并简单地将它的一个实例传递给您的应用程序中的dispatcher webroot / index.php 前控制器:

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

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

这篇关于CakePHP 3.x:如何扩展Request类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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