找不到CakePHP 3.0供应商类 [英] CakePHP 3.0 vendor class not found
问题描述
我通过将一个外部类添加到一个蛋糕3.0应用程序,将它放在/ vendor / name文件夹,并要求从一个组件,如下:
require_once($ _SERVER ['DOCUMENT_ROOT']。'/ project / vendor / external / testClass.php');
但是当我尝试getInstance的类 - 我收到错误
未找到类'App\Controller\Component\ Test_Class'
我从组件(因此是\Controller\Component)调用此方法。
$ bCakePHP 3.0使用命名空间。因此,对供应商类使用正确的命名空间,或者如果它不使用命名空间,在使用它时使用反斜杠作为类名的前缀。
例如 $ object = new \Test_Class();
。
I'm adding an external class to a cake 3.0 app by putting it to /vendor/name folder and requiring it from a component like this:
require_once( $_SERVER['DOCUMENT_ROOT'].'/project/vendor/external/testClass.php');
But when I try to getInstance(); of a class - I get an error
Class 'App\Controller\Component\Test_Class' not found
I am calling this from a component (thus the \Controller\Component).
What is it that i'm doing wrong?
CakePHP 3.0 uses namespaces. So use proper namespace for your vendor class or if it's not using namespaces prefix the class name with backslash when using it.
E.g. $object = new \Test_Class();
.
这篇关于找不到CakePHP 3.0供应商类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!