Cakephp 3加载供应商文件 [英] Cakephp 3 loading vendor files

查看:76
本文介绍了Cakephp 3加载供应商文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在cakephp 2中,当我需要全局加载供应商或相关类时,我在bootstrap.php或核心php中添加了需求或应用程序。

In cakephp 2 when I need a vendor or related class to be loaded globally, i was adding require or app use inside bootstrap.php ot core php.

在cakephp 3我应该在哪里要求供应商文件?我不想在使用供应商文件的每个类和模板文件中声明供应商要求。

In cakephp 3 where should I require vendor files ? I dont want to declare vendor require in every class and template file that I use my vendor files.

http://book.cakephp.org/3.0/zh-CN/core-libraries/app.html#loading-vendor-文件

推荐答案

供应商文件是3rdparty文件。您自定义的静态实用程序类不是供应商文件,而是您的应用程序文件。您可以将它们放在 src / Lib / 下。只需确保为类使用正确的名称空间,并在需要使用类的任何地方添加正确的 use 语句即可。

Vendor files are 3rdparty files. You custom static utility classes are not vendor files but rather your app files. You can put them under src/Lib/. Just ensure to use proper namespace for the classes and add proper use statement wherever you need to use your class.

例如如果您的lib类是 src / Lib / FooBar.php ,则它的类名应为 App\Lib 和使用语句将是使用App\Lib\FooBar

For e.g. if your lib class is src/Lib/FooBar.php then it should have classname App\Lib and the "use" statement would be use App\Lib\FooBar.

这篇关于Cakephp 3加载供应商文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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