TP Framework Foundation (i)

Source: Internet
Author: User

"Use Frame"

Official website: thinkphp.cn. The thinkPHP3.2 version is currently recommended

First, the structure of the directory
"Thinkphp folder, is the core file of thinkphp, the content is not allowed us to modify
Public is a common folder in which you can write your own things.
Application we set up the project folder (public and application inside the original files can be deleted, equivalent to two empty folders)
The index.php in the TP folder is the entry file for all Programs

Conf folder--configuration file, which almost includes all configurations about thinkphp. However, you cannot modify it in this folder. If you want to configure the thinkphp, you need to check the configuration, configure the name of the variable, and then copy to your own configuration file, change the variable
Library folder contains almost all of the core classes, in the Think folder under the Library folder

"Mode folder--model

"TPL folder, templates

"Framework Project Deployment"

Deploy a shop project using the TP Framework

Steps:

To create a portal file:

1. Create a portal file under the thinkphp directory index.php

"Define defines constants

Define (' App_debug ', True)

True: The debug mode is turned on, it is recommended that the development phase be turned on so that errors can be reported in detail when developing
False: Production mode, error will not report detailed error information, not conducive to the development

2. access to the Portal file system will automatically create the corresponding application directory file shop

3. Open the Home folder

"MVC pattern"

M: Model Data layer, responsible for data manipulation

V: View View layer, responsible for displaying views (that is, templates, static pages)

C: Controller controllers to implement business logic


"Controller access and routing resolution"

Locate the specified controller through the URL address get parameter and make the corresponding method call request

HTTP// URL /index.php?m= module name &c= controller &a= method

The above URL address information code is not elegant, not secure.

The TP frame URL address can be made up of the following four

1.http://URL/index.php?m=xx&c=xx&a=xx Basic get mode (a represents action action)

2.http:// url /index.php/ module / controller / operation method Path mode PathInfo

3.http:// URL / module / controller / operation method R Ewrite Rewrite mode

4.http:// url /index.php?s=/ module / controller / method Compatibility mode

Specific URL address mode settings ( config file thinkphp/conf/convertion.php)

Url_model = 0/1/2/3 represents four URL address modes respectively

config.php is the configuration file for our current project, and we can modify the file to reach the directory of configuration variables.

This file will overwrite the convertion.php configuration variables during system operation.

Include "convertion.php";

Include "config.php"; after the introduction of the file to the first introduction of the file configuration variables to cover out

Our system is compatible with the use of 4 URL address mode

The system will sometimes automatically create a URL address, which will be created using the URL address According to the current schema

Shortcut function U (); create a URL address

We learned the following from the URL address pattern:

1. We learned the configuration variable (core configuration variable conversion.php, current application configuration variable config.php)

2. shortcut function U ("module / controller / method ") according to parameter and URL pattern Create a corresponding URL address

3. Adjust the frame mode to develop the debug mode

The default IndexController.class.php controller, the controller is a class, inherits the controller parent class, inside the index method is called the operation in the controller

When accessing the portal file, the default method in the default controller is actually accessed (conf->convention.php in the thinkphp folder)

"' Url_model ' = 1 is the default auto-generated path, generated according to the path of 1. In your own project, if you want to create a URL, you create the path by 1.

"Development, production model"

Development Debug Mode: The system needs to load approximately five files index.php define ("App_debug", true);

Production mode: The system only needs to load very little about 7 files in the portal file

index.php defined in: define ("App_debug", false);

Save resources by saving a lot of file development, shutting down the system overhead

To display trace information on the page, you need to be in your own configuration file:

"Recommended when developing (in your own project configuration)
' Show_page_trace ' =>true, written in the configuration, the lower right corner of the logo appears, click will show some of the execution of the details

"In production mode, the common-runtime.php file is cached and the->runtime->common-runtime.php file (many files are integrated in this file) under the Shop project folder that you created.

"Controller and corresponding method creation"

The controller is the core of the MVC pattern, andTP has an Index controller by default:

The index controller has an operation method:Index

When we access the http://localhost:8080/Thinkphp/index.php portal file, we will access the index under the index controller by default. Method

If you want to create a controller yourself Login:

1. Create a new controller file under the \shop\home\controller folder LoginController.class.php

Note: File naming rules, named according to the Hump (create controller, capitalize the first letter of the Controller)



2. Open the file, build the controller Login class inside

3. If you want to customize the action method, Add a function login ()to the Controller login class:

In this way we have completed the establishment of the controller and operation method, if you want to access our login controller under the login method:

4. In the controller if you want to invoke the template in the view layer:

If you visit again, you will find an error:

Cause: The template file is not created and we are going to create the template file

"Parent of all Controllers controller location: tinkphp->library->think->controller.class.php

"TP framework has two root namespaces

Namespaces used in other places, 1.thinkphp\libraray
2.Home if used in a module, the root namespace is Home

Can have multiple methods under the same controller, and each method can be accessed individually

"The controller corresponds to a template folder, each method in the controller, corresponding to each page in the template folder. The folder in view must be consistent with the name of the controller, consistent in case,

"Namespace (equivalent to a virtual folder)

In MVC, there is a saying: the convention is better than the configuration

The role of the framework: conducive to a clear division of labor at the time of development

TP Framework Foundation (i)

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.