About the constructor in the controller class in thinkphp

Source: Internet
Author: User
Tags autoload
About the constructor in the controller class in thinkphp
Public function _ construct () {Hook: listen ('Action _ in ', $ this-> config); // instantiate the view class $ this-> view = Think :: instance ('think \ view'); // The controller initializes if (method_exists ($ this, '_ initialize') $ this-> _ initialize ();}

This is the controller class constructor code in the tp framework.
View should be introduced into the controller through this function, but how is the Hook class and Think class introduced into the controller class.
Can I directly use the Hook class or Think class without any use or require?


Reply to discussion (solution)

ThinkPHP first executes the Think class in Think. class. php.
There are
Spl_autoload_register ('think \ Think: autoload ');
Registered methods for automatically loading class files
This method will be called to load classes that are not in the memory.

ThinkPHP first executes the Think class in Think. class. php.
There are
Spl_autoload_register ('think \ Think: autoload ');
Registered methods for automatically loading class files
This method will be called to load classes that are not in the memory.



Found... I feel that the tp framework is well designed .....
Can the moderator explain how thinkphp makes Think class in Think. class. php run first?

Project entry:

 /// + Outputs // application entry file // Check the PHP environment if (version_compare (PHP_VERSION, '5. 3.0 ',' <') die ('require PHP> 5.3.0! '); // Enable the debugging mode. it is recommended that you enable the annotation of the deployment phase in the development phase or set it to falsedefine ('app _ debug', True ); // define the application directory define ('app _ path ','. /Application/'); // introduce the ThinkPHP entry file require '. /ThinkPHP. php '; // It's so simple that no code is needed in the end

The last line of the ThinkPHP. php file is
Think\Think::start();

In this way, the entire system will be activated.

Project entry:

 /// + Outputs // application entry file // Check the PHP environment if (version_compare (PHP_VERSION, '5. 3.0 ',' <') die ('require PHP> 5.3.0! '); // Enable the debugging mode. it is recommended that you enable the annotation of the deployment phase in the development phase or set it to falsedefine ('app _ debug', True ); // define the application directory define ('app _ path ','. /Application/'); // introduce the ThinkPHP entry file require '. /ThinkPHP. php '; // It's so simple that no code is needed in the end

The last line of the ThinkPHP. php file is
Think\Think::start();

In this way, the entire system will be activated.



O (∩) O thank you

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.