问题
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?
回答1:
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();
.
来源:https://stackoverflow.com/questions/29866131/cakephp-3-0-vendor-class-not-found