Think questions about the PHP namespace ask for answers.

Source: Internet
Author: User

If this is the directory structure

This is test.class.php the inside of the code

php
  
   

这是 IndexController.class.php 下的代码

php 

我想达到的效果是在 test.class.php 下不把命名空间命名成 namespace Common\Common; 而是命名为 namespace Common; 也能在 IndexController.class.php 实例化 test.class.php 这样就可以减少一个目录,因为我在另一个业务里有一个目录名是变量 想跳过那个目录 能实现的实例吗 真心求解答

Reply content:

If this is the directory structure

This is test.class.php the inside of the code

php
  
     

这是 IndexController.class.php 下的代码

php 

我想达到的效果是在 test.class.php 下不把命名空间命名成 namespace Common\Common; 而是命名为 namespace Common; 也能在 IndexController.class.php 实例化 test.class.php 这样就可以减少一个目录,因为我在另一个业务里有一个目录名是变量 想跳过那个目录 能实现的实例吗 真心求解答

can.

Recommended article: PHP namespace FAQ

If you use automatic loading, you can't change the rules of automatic loading, you can use import or vendor to introduce class libraries, there is no need to tangle. If you really want to do this, then Class Library mapping can help you. View Document: Http://document.thinkphp.cn/manual_3_2.html#autoload

  • 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.