Thinkphp Framework Foundation

Source: Internet
Author: User

thinkphp Introduction of PHP Framework

Real project Development Steps:

    1. Many people at the same time develop projects, collaborative development projects, reasonable division of labor, Efficiency has improved (code style is different, division of labor is not good)
    2. Testing phase
    3. On-line operation
    4. Maintenance, modification, and upgrade of the project (individual maintenance project, very difficult, code style is not the same)
    5. Stable operation phase of the project
    6. Project stopped running (the old project staff have all left, the new development project)

Problem:

1. Multi-person development project, the Division of labor is unreasonable, (HTML PHP mysql)

2. Code style is not the same, late maintenance is very difficult

3. Project life cycle is very short, project life is not continuity, resulting in waste of resources, personnel waste

4. The project does not adapt well to customer needs, reaching.

Other relevant frameworks

1. Zendframework Zend PHP Language Company released the official framework, heavyweight (multi-function)

2. Yii American Chinese Development Framework, Xue Qiang, Qiang, heavyweight framework, pure OOP framework

3. CI CodeIgniter Lightweight framework, fast development, flexible deployment

4. CakePHP foreign framework, heavy-weight, slow

5. Symfony Foreign Heavyweight framework

6. thinkphp Lightweight frame, Chinese frame, easy to get started

What frame:

A bunch of code collection, inside there are variables, functions, classes, constants, there are many design patterns MVC, AR database, Singleton and so on.

The framework can save us the 50-60% of our work, and all of our energies are focused on the business level.

Why use frames?

1. The framework can help us set up the program system quickly, stably and efficiently.

2. The system has been maximized for its maintainability, flexibility, and adaptability to the needs of its customers as a result of the use of the framework.

3. The process of using the framework allows us to focus all of our attention on the business level without having to care about the underlying architecture of the program.

Second, thinkphp 3.2 version of the introduction

1. Unzip the files in the Thinkphp folder and change the entry file to index.php

2. conf Configuration folder

3. In the Library core resource pool

4. Core document Think in Library core resource pool

III. Deployment of Framework projects

1. Open the Index.php entry file and change the original application to Jiaowu

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

3. Open the Home folder

IV. MVC pattern

Mvc:model model Model (data) Layer View View Layer Controller controller Logic layer

M: Operational data (data connection, data access)
V: Provide display template
C: Implementing Business logic

Three relations:

MVC: Conventions are better than configuration

Five, controller access and routing resolution

Controller folder:

Controller naming method: IndexController.class.php-----Index is the name of the controller
Namespace: namespace, equivalent to file directory
Public Function index is called an action (action) under a controller

Action: The method that is placed inside the controller


Previously accessed by: Access to specific pages
How MVC accesses: access to operations under the Controller (method), not a specific page


5.1 MVC Four Ways to access:
Access steps:
1. Locate the entry file index.php
2. Re-find the module, controller, method name (operation)

1.http://URL/index.php?m=xx&c=xx&a=xx basic Get mode

Example 1:

Browser address: Http://localhost:8080/thinkphp/index.php?m=Home&c=index&a=index


Results:

Example 2:


Browser address: Http://localhost:8080/thinkphp/index.php?m=Home&c=index&a=Login


Results:
2.http://URL/index.php/module/controller/operation method path mode PathInfo (recommended this way)
Http://localhost:8080/thinkphp/index.php/Home/index/Login

3.http://URL/module/controller/operation method rewrite override mode
Http://localhost:8080/thinkphp/Home/index/Login
4.http://URL/index.php?s=/Module/controller/method Compatibility mode
Http://localhost:8080/thinkphp/index.php/?s=Home/index/Login
Http://localhost:8080/thinkphp/?s=Home/index/Login

2, 3, 4 results: Welcome to Login

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


The control mode here is not to control the access, is to control the generated


How do I modify the configuration?
Do not modify in the original file, but copy it to your own project file.
1. In Jiaowu, locate the config.php in the Conf folder under the home folder

2. In IndexController.class.php, create a path

U (): shortcut function for making URL address

Operation Result:


Note: If it is under the current controller of the current module, you can write only the method
If it is under the other controller of the current module, write the controller and method
If it is under other modules, the module, controller, method name (operation) must be written


3. Modify the configuration values:

' Url_model ' = 0,
Running Result:/thinkphp/index.php?m=home&c=index&a=login

' Url_model ' = 2,
Running Result:/thinkphp/home/index/login.html

' Url_model ' = 3,
Running Result:/thinkphp/index.php?s=/home/index/login.html

5.3 In the controller if you want to invoke a template in the view layer:

Now there is a controller in the controller is IndexController.class.php, there is a method is Public function index ()

There is a index.html file under the view file,

In IndexController.class.php:

index.html file:

Operation Result:

Cause: The above two do not correspond to each other, the template file is not created correctly, this time we are going to create a template file

How to create the template correctly:

If we want to access the index method in the index controller, we first create a template folder corresponding to the index controller, which corresponds to the index controller:

Write the code to be displayed in the index.html:

 Public "-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

Operation Result:

Vi. Development and production models

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

Production mode: The system only needs to load very little about 12 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

The commom~runtime.php file appears when you develop the mode, and the debug mode does not

To display trace information on the page, you need to add a line of code to your profile config.php:

Thinkphp Framework Foundation

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.