I'm here
ThinkPHP
Of
index.php
Add the following:
// 添加第三方库自动加载require './vendor/autoload.php';
However, when using the prompt 类不存在
.
But in Controller
addition require
, it can be used.
What is the cause of it? Is there only one class loader? Thinkphp also wrote a, resulting in a class loader that covered the composer?
Do you have any idea? Thank you.
I see this question inside, there is a answer, said is in the English document inside.
Spl_autoload_register can handle situations where multiple loaders are required, in which case Spl_autoload_register will sequentially invoke the previously registered loader. As a comparison, __autoload can only be defined once because it is a function.
There should be more than one.
Reply content:
I ThinkPHP
added the index.php
following:
// 添加第三方库自动加载require './vendor/autoload.php';
However, when using the prompt 类不存在
.
But in Controller
addition require
, it can be used.
What is the cause of it? Is there only one class loader? Thinkphp also wrote a, resulting in a class loader that covered the composer?
Do you have any idea? Thank you.
I see this question inside, there is a answer, said is in the English document inside.
Spl_autoload_register can handle situations where multiple loaders are required, in which case Spl_autoload_register will sequentially invoke the previously registered loader. As a comparison, __autoload can only be defined once because it is a function.
There should be more than one.
5.0版本支持Composer安装的类库的自动加载,你可以直接按照Composer依赖库中的命名空间直接调用。
Meaning that, thinkphp already put composer of that set of automatic loading mechanism merge into, you just need to download the dependent class library with composer, download good, in need of place with use to import namespace can, do not need to write on their own require APP_PATH.'../vendor/autoload.php';
.
Poof, I know what caused the ... Before, require
ThinkPHP.php
after the introduction, in fact, at the require './ThinkPHP/ThinkPHP.php';
time, it has started in 执行ThinkPHP
the core code, has been routed into the Controller
inside of the ...
Wrong:
// 引入ThinkPHP入口文件require './ThinkPHP/ThinkPHP.php';// 添加第三方库自动加载require './vendor/autoload.php';
Right:
// 添加第三方库自动加载require './vendor/autoload.php';// 引入ThinkPHP入口文件require './ThinkPHP/ThinkPHP.php';