ThinkPHP namespace problems?

Source: Internet
Author: User
Namespace in thinkphpframework {code ...} the problem is that namespaceHomeController; the first line of code declares the space of this file, so the IndexController class is under the namespace of HomeController. This class... // namespace problems in thinkphp framework


  

The problem arises. namespace Home \ Controller; the first line of code declares the space of this file,
So the IndexController class is under the namespace Home \ Controller,
This class inherits the Controller class. At this time, there is no Controller class under Home \ Controller,
Although use Think \ Controller; imports another space, why?
Class IndexController extends Controller does not report an error? This is because no Controller class exists under Home \ Controller.
Why not write it as class IndexController extends Think \ Controller?

Reply content:

// Namespace problems in thinkphp framework


   

The problem arises. namespace Home \ Controller; the first line of code declares the space of this file,
So the IndexController class is under the namespace Home \ Controller,
This class inherits the Controller class. At this time, there is no Controller class under Home \ Controller,
Although use Think \ Controller; imports another space, why?
Class IndexController extends Controller does not report an error? This is because no Controller class exists under Home \ Controller.
Why not write it as class IndexController extends Think \ Controller?

phpuse Think\Controller;

This line of code has already imported the namespaceThink \ Controller.ControllerCategory

If you do not use:

phpuse Think\Controller;

You need to write

phpclass IndexController extends \Think\Controller\Controller {}

Try the following two sentences:

$controller = new Controller();//$controller = new IndexController();var_dump($controller);

The controller class is automatically loaded into the framework.

Http://www.php-internals.com/book/ is recommended to see how the kernel source code is achieved

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.