问题描述
我有自定义的实用程序类,包含一些常用的方法,它位于src / Utility / UtilityClass。
I have custom utility class that contains some methods for general use and it is located in src/Utility/UtilityClass.
我可以在控制器中包括Utility类。例如
I can include the Utility class in controller .e.g.
use App\Utility\ArrayUtil;
然后在我的控制器中调用类
and then call the class in my controllers e.g.
ArrayUtil::myMethod();
我需要在引导程序中包含UtilityClass,因此它应用于应用程序,所以我可以在模型,模板和其他控制器中重用它。
And it works. I need to include the UtilityClass in bootstrap so it applies all over the application so I can reuse it in models, templates and other controllers as well.
我试图加载它在config / bootstrap.php但我得到这个错误:
I tried to load it in config/bootstrap.php but I get this error:
任何想法
推荐答案
use App\Utility\ArrayUtil;
如果您在多个视图中使用此实用程序,那么我建议您编写此行在模板/布局/ default.ctp,因为所有的模板将是这一部分。
If you're using this utility in multiple views, then I'd suggest you to write this line in Template/Layout/default.ctp, since all templates would be a part of this.
希望这有助于。
和平! xD
这篇关于在应用程序cakephp 3中包含实用程序类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!