Why is the thinkphp add composer automatic loading invalid?

Source: Internet
Author: User
Tags autoload
I'm here ThinkPHPOf index.phpAdd 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';
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.