Thinkphp as a representative of the PHP framework, after years of development, by more and more companies and developers of all ages. I also take part of the time to learn this excellent framework. In the beginning of learning this framework, it is best to learn through examples, more easily combined with the actual production situation, promote the effect of learning Here I will choose the ThinkPHP3.2-based content management framework Onethink developed by the thinkphp team to learn from the implementation process of understanding it → familiarize yourself with the details of the process → learn the template tags → I actually use the label → to understand its actual implementation process ... Through such a process to familiarize yourself with how to develop a CMS system based on thinkphp.
This is the beginning of the study notes: (a) familiar with the implementation process, followed by the onethink of the first page content generated flow, analysis of the user after accessing a URL, the program is how to deal with, for follow-up detailed analysis to pave the way.
Local build Onethink environment, first Access first installed, after successful first browse the function of the CMS; Front desk (homepage, List page, article page), Backstage (System Information, Content release audit, user rights behavior management, System Setup, column management, database backup, plug-in management), Are the general functions of the content management system.
Visit the website home page index.php, followed by the implementation of the process to go through, the details do not delve into the variable, not quite understand, direct var_dump () output to see:
1. index.php--Home Portal page, version determination, whether to open debugging, introduce thinkphp framework
Path: './index.php '
The PHP version should be judged to be 5.3.0 or more: Version_compare (php_version, ' 5.3.0 ', ' < ');
System Debug Settings: Define (' App_debug ', true);
App Directory settings: define (' App_path ', './application/');
Cache Directory settings: define (' Runtime_path ', './runtime/');
Introduction of Thinkphp:require './thinkphp/thinkphp.php ';
2. thinkphp.php--thinkphp framework of the entry file, define a variety of constants, judge the system environment, the initialization of the application
Path: './thinkphp/thinkphp.php '
Define constants: Version number think_version, URL pattern definition (4 modes), class file suffix ext, SAE environment, common system path constants (such as Think Class Library directory, application public directory, cache directory, configuration directory, etc.);
Introducing the core class Think.class.php:require Core_path. ' Think '. EXT;
Application initialization: Think\think::start (); namespace \ Class Name:: Method (); The namespace is used here.
3. Core classes of the think.class.php--framework, initializing applications, loading configurations, class libraries, error and exception handling, instantiating objects
Path: './thinkphp/library/think/think.class.php ' declaration: Think\think
Start () method: Load the required classes, configurations, language packs, whether the cache is needed, run the application
① Setting Method: Spl_autoload_register (' think\think::autoload '); The method of automatically loading class, and some error exception handling methods;
② distributed storage class initialization, for reading, writing, deleting files; Storage::connect (Storage_type);
③ Development mode does not cache the loaded core class file $runtimefile, user mode caches all classes that need to be referenced into the same file and speeds up subsequent access.
④ an array of file paths such as the application's configuration file, required functions and class files, line extensions, and so on $mode;include './thinkphp/mode/common.php '
⑤ the file that handles each path in the $mode array in a cyclic load;
⑥ checks if the application directory structure exists and does not exist, the directory structure is generated by default (this is a new app for thinkphp and is used on first visit)
⑦ Start running application App::run (); That is: './thinkphp/library/think/app.class.php '
4. app.class.php--loading public file configuration, URL parsing, calling the corresponding Controller method
Path: './thinkphp/library/think/app.class.php ' declaration: Think\app
Run () Method:
①app::init ();
Load_ext_file load the application's public file (./application/common/common/) configuration (./application/common/conf)
Think\dispatcher::d ispatch (); URL parsing, obtaining the controller index, method index
②app::exec (); Execute the application, and create an instance of the new controller homeconstroller, i.e. object;
Create Controller instance: $module = Controller (controller_name,controller_path); namely =new Indexcontroller ();
Use the PHP reflection mechanism to get the action method object, $method = new \reflectionmethod ($module, $action);
Perform this method: $method->invoke ($module); No parameters when executed, Access home page by default to perform this
$method->invokeargs ($module, $args); Execute when there are parameters;
The above is the controller executed. Index method in/application/home/controller/indexcontroller.class.php
5. indexcontroller.class.php--Application Home Default first page index controller
Path:./application/home/controller/indexcontroller.class.php
index () method:
$category = D (' category ')->gettree (); Call the Gettree () method in the Category module (./application/home/model/categorymodel.class.php) to get the data for the site column, where category corresponds to the data table name;
$lists = D (' Document ')->lists (null); Call the lists () method in DocumentModel.class.php as above;
$this->assign (' category ', $category);//Assign column array data to category labels
$this->display (); Parse template, output, template (./application/home/view/default/index/index.html)
This takes advantage of " template inheritance ", see:
Http://document.onethink.cn/manual_1_0.html#onethink_3_8
In this case, the process of visiting the homepage of the site ends, where the background admin.php and installation of the install.php execution process is similar, here does not do the narrative. In this common function file (./thinkphp/common/functions.php), a single uppercase method that is called directly is used.
Finally remind yourself that learning is a gradual process, it takes a time to accumulate, it is impossible to look at it, need to follow this process more than a few times, and then familiar with the details of the process of implementation, a lot of practical coding practice, to truly master!
Keep trying!
(i) familiar with the implementation process--ThinkPHP3.2-based content management Framework Onethink Learning