thinkphp Frame One

Source: Internet
Author: User
Tags php language zend

1.1 Concept of the framework

The framework is actually a collection of reusable code, the framework code is the framework of the Code, not the business logic code, framework code protection class. Methods. Functions and so on, the framework code is formed according to a certain set of rules.

1.2 Problems encountered while not using framework development

1. Code authoring does not have a uniform specification

2. The project function is not very well split

3. A partial minor change may affect the global

4. Project upgrade is more troublesome

1.3 Benefits of using frames

1. Code style that facilitates team unification

2. Focus on the business logic without concern for the underlying framework

3. Fast, stable and efficient construction procedures

4. Save a lot of code

5. Late maintenance upgrade is very convenient

1.5 Related frameworks

1. Zendframwork: Zend Official release (Zend Company is to maintain the PHP language company), the function is very powerful, is a heavyweight framework

2.YII: A heavyweight framework developed by the Chinese, which puts the reusability of code to its fullest

3.cakePHP: Foreign frame, slow speed

4.symfony: The framework of foreign countries

5.CI: (code igniter), lightweight frame, fast running speed

6.ThinkPHP Framework, free, open source, fast, simple object-oriented (the code is both object-oriented and process-oriented), formerly named fcs,2007 New Year's Day, renamed to Thinkphp

1.6 thinkphp File structure

Download the TP framework from the official website of http://www.thinkphp.cn/, unzip it after downloading is complete, the first category of thinkphp is the core code of our framework, similar to the framework folder

Conf: Configure folders for all projects built in this TP framework to use

Library: Class Libraries

1.7.1 thinkphp under the Library folder

Behavior: The class of the Framework runtime helper

think:thinkphp Core Code

Vendor: Some of the third-party plugins

Think folder under 1.7.2 thinkphplibrary

Several files to be aware of:

Controller.class.php: Base Controller

Model.class.php: Basic model

Think.class.php: Each request is executed with a file

View.class.php: Base View

1.8 Structure of the building frame

Create a new index.php (portal file) under the site and enter it in index.php:

Define (' App_path ', './application/'); Define project folder, need to end with/

Require './thinkphp/thinkphp.php '; Include thinkphp.php file

Note: Multiple entry files can be supported in the TP framework (i.e. support for multiple projects);

1.8.1 define (' App_path ', './application/')

Define the project folder, the first time the page is executed, if there is no application folder, the application folder is created automatically. When the thinkphp.php file is executed, the thinkphp frame structure is automatically built for the first time.

1.9 Creating a Controller

The controller is a class file with the following specifications:

1. Controller folder stored in the module (platform) folder

2. Class Name: Controller +controller, using Pascal's name method

3. class name and file name

4. File name ends with. class.php

5.ThinkPHP using UTF-8 encoding by default

6. Try to be case-sensitive, there is no problem in Windows, but case-sensitive in Linux

Note When creating the controller namespace and introducing the base controller.

Route 4 in 1.10 thinkphp

To pinpoint to a method, you need 3 parameters: platform. Controller. Method, these three parameters.

A) Normal mode:

Syntax:/HTTP URL/index.php/m= Module &c= controller &a= method

b) Pathinofo () mode:

Syntax:/HTTP/URL/index.php/module/controller/method

c) Compatibility mode:

Syntax:/HTTP/URL/index.php?s=/module/controller/method

d) rewrite rewrite mode:

The URL customization feature overrides the route so that the URL can be introduced and the actual path is hidden.

Pseudo-static technology is the rewrite mode.

Configuration items that need to be used:

' url_router_on ' = = true,//Turn on routing

' Url_route_rules ' = Array (

' Test ' = ' home/goods/test ',

),//Routing rules

REDIRECT Pass parameters

1.11 Definitions. Calling templates

1.11.1 rules

The TP framework invocation template is very simple and powerful. It has some rules of its own.

1. Templates are placed in the view directory

2. One controller corresponds to a folder, one method corresponds to one page

1.11.2 calling a template

$this->display ();

1.11.3 assigning values to variables in the controller

$this->assign (' name ', ' Tom ')//The first method

$this->sex= ' man '; The second method of

1.11.4 the value in the template

{$name}

1.12 Project Grouping

A project is divided into at least two groups, one foreground, one backstage, and each group has its own MVC. A foreground grouping is automatically generated when the TP framework automatically generates the project schema.

Create a new Admin folder (background folder) in the same directory as the home sibling and create your own MVC in the folder

1.13 System Constants

__SELF__: The address of the current request

__MODEL__: Current Module

__CONTROLLER__: Current Controller

__ACTION__: Current method

Get_defined_constants (True) displays all constants and True indicates group display.

Question: The __controller__ constant is a constant of PHP, and we find that it can be parsed directly by writing this constant in the template, why PHP constants can be output in HTML templates? Define a constant name in PHP, how do I output the value of name in the template?

Add a string substitution in the ContentReplaceBehavior.class.php file Templatecontentreplace () method

1.14 Displaying log information at the bottom of the page

' Show_page_trace ' + true//display log information at the bottom of the page

A small green icon appears in the lower right corner of the page after configuration

1.15 TP production and development model

Define (' App_debug ', TRUE); Development model

Define (' App_debug ', false); Production mode

1.15.1 Development Model

1. The error prompt is more friendly

2. Changes to the code will immediately show the effect

3. Low execution efficiency

1.16.2 generation Mode

1. Error hints are blurred

2. Many core code files will be made into a cache file (common~runtime.php), so that the original request to load a lot of files now just load a file. Save a lot of the overhead of opening and closing.

thinkphp Frame One

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.