TP Framework learning is generally from the understanding of the framework of the basic structure of the beginning, each file has its own role, the review of my TP Framework from the basic structure began to talk about.
First, the acquisition of thinkphp
Http://www.thinkphp.cn This is the official website, my TP Study uses the 3.1.3 full version
After downloading, change the file name to thinkphp, and then put it under your project folder, for example, we want to do the project is BBS, that is, message boards.
Two . Building a basic structure //TP The construction of the medium structure is automatic.
TP structure is automatic , we only need to build a index.php file in the BBS folder to write code to run the directory structure can be implemented. the index.php code is as follows:
<?php
1. Determine the foreground folder name Home
Define (' App_name ', ' Home ');
2. Determine the application path
Define (' App_path ', './home/');
3. Turn on Debug mode
Define (' App_debug ', true);
4. Apply the core file
Require './thinkphp/thinkphp.php ';
?>
Of course, Home is our foreground folder, and to generate the Admin folder in the background, the method is similar to the above, only need to write a file, called admin.php, content, you only need to index.php folder under the Home instead Admin can be, namely:
<?php
1. Determine the background file name Admin
Define (' App_name ', ' Admin ');
2. Determine the application path
Define (' App_path ', './admin/');
3. Turn on debug mode to prevent the cache from causing debugging problems
Define (' App_debug ', true);
4. Apply the core file
Require './thinkphp/thinkphp.php ';
?>
After the two folders have been written, the final step is to build, run: Enter http://localhost/bbs/index.php in the browser, if the display welcome to use thinkphp on behalf of our files run successfully. We will find in the folder, automatically created a folder called Home There are all kinds of files, we do not hurry to understand what these files are doing, we have to proceed to the next step, that is the Admin The folder is also built up. The method is the same as above, except the URL is different:http://localhost/bbs/admin.php carriage return page also welcome to use thinkphp, we will find the admin The document was also built. Well, the building work is finished, so let's see what those files are for.
thinkphp Core Document Introduction // Understanding, because we are using the framework, and we do not manipulate the original framework file, but the operation of the subsequent generation of their own files, the structure is basically similar to the original framework.
Iv. description of the directory structure
| -- index.php// Main entry file
| -- admin.php// Background Entry file
| -- Public // public folder, used to put Css , Js , Images , Web page editor, Uplode documents, etc.
| -- Home// foreground folder (under Face Home folder for detailed explanation)
| -- Admin// Background folder (with Home similar)
Five, Home project directory Structure and Description:
Home Foreground App folder
├─Common Project common file directory (can be used to put public methods, such as empty operation function)
├─conf Project configuration directory (where config.php can be configured for the project) "Focus"
├─Lang Project Language directory
├─lib Project Class library catalogue "Focus"
│├─action Class Library directory (the local format of the file is IndexAction.class.php)
│├─Behavior behavior Class Library Directory
│├─model Model Class Library directory (base format is IndexModel.class.php)
│└─Widget widget class Library Directory
├─ Runtime project run-time directory
│├─ cache template Caching Directory
│├─ data Cache directory
│├─Logs log file directory
│└─temp Temporary cache directory
└─TPL Project Template directory "Focus" a class corresponding to a folder, such as IndexAction.class.php There is a template folder called Index , If there is a method of index in the class, you usually need an HTML file corresponding to the method name , for example:
Class Indexaction extends action{
Public Function index () {
$this->display ();
}
}
The above code means that there is a method of index in the class with index,$this->display (); is to show the meaning of this page so that the system defaults to Under the TPL folder , look for the index.html file under the index folder and display the contents
Vi. Introduction tothinkphp (Additional understanding of the MVC mechanism)
M-model Model work: Responsible for data operations, such as the following three large automatic.
V-view View (template) Work: Responsible for the foreground page display
C-controller Controller (module) Work: Description function