Table of Contents
ThinkPHP framework one, ThinkPHP framework
Home Backend Development PHP Tutorial ThinkPHP framework 1, ThinkPHP framework_PHP tutorial

ThinkPHP framework 1, ThinkPHP framework_PHP tutorial

Jul 12, 2016 am 09:01 AM
thinkphp

ThinkPHP framework one, ThinkPHP framework

1.1 The concept of framework

A framework is actually a collection of reusable codes. The code of the framework is the code of the framework architecture, not Business logic code, framework code protects classes, methods, functions, etc. The framework code is combined according to certain rules to form a framework.

1.2 Problems encountered when developing without using a framework

1. There is no unified specification for code writing

2. Project functions cannot be divided well

3. A small local change may affect the overall situation

4. Project upgrades are troublesome

1.3 Benefits of using frameworks

1. Conducive to team unification Code style

2. Concentrate all your energy on business logic, no need to care about the underlying framework

3. Build the program quickly, stably and efficiently

4. Save a lot of code

5. Later maintenance and upgrades are very convenient

1.5 Related frameworks

1. zendframework: zend official release (zend company is a company that maintains and upgrades PHP language), functions Very powerful, it is a heavyweight framework

2. Yii: A heavyweight framework developed by Chinese people. This framework maximizes the reusability of code

3.cakePHP: Foreign frameworks, slow

 4.symfony: foreign frameworks

 5.CI: (code Igniter), lightweight framework, fast running speed

 6. ThinkPHP framework, free, open source, fast, simple object-oriented (the code inside is both object-oriented and process-oriented), formerly known as FCS, changed its name to ThinkPHP on New Year's Day 2007

1.6 ThinkPHP file structure

Download the TP framework from the official website http://www.thinkphp.cn/ and unzip it after the download is complete. ThinkPHP in the first directory is the core code of our framework, similar to the Framework folder

Conf: Configuration folder, used by all projects built on this TP framework

Library: Class library

1.7.1 Library folder under ThinkPHP

Behavior: Framework runtime auxiliary classes

Think: ThinkPHP core code

Vendor: Some third-party plug-ins

1.7.2 Think folder under ThinkPHPLibrary

Several files to note:

Controller.class.php: Basic controller

Model.class.php: Basic model

Think.class .php: Each request must be executed with files

 View.class.php: Basic view

1.8 Structure of the framework

Create a new index.php under the site (Entry file), enter in index.php:

define('APP_PATH','./application/'); //Define the project folder, which needs to end with /

require './ThinkPHP/ThinkPHP.php'; //Contains the ThinkPHP.php file

Note: Multiple entry files can be supported in the TP framework (that is to say, multiple projects are supported);

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

Define the project folder. When the page is executed for the first time, if there is no application folder, the application folder will be automatically created. . When the ThinkPHP.php file is executed, the ThinkPHP framework structure will be automatically built for the first time.

1.9 Create a controller

A controller is a class file with the following specifications:

1. Stored in the Controller folder
under the module (platform) folder
2. Class name: Controller, using Pascal nomenclature

3. The class name and the file name have the same name

4. The file name ends with .class.php

5. ThinkPHP uses UTF-8 encoding by default

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

Pay attention to the namespace when creating the controller and the introduction of basic controllers.

1.10 ThinkPHP’s 4 routes

To accurately locate the method, three parameters are required: 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 function can make the URL simple and hide the truth by rewriting the route. path.

Pseudo-static technology is the rewrite mode.

Required configuration items:

'URL_ROUTER_ON' => true, //Enable routing

'URL_ROUTE_RULES' => array(

'test' => 'home/Goods/test',

), //Routing rules

Redirect passing parameters

1.11 Definition. Call template

1.11.1 Rules

TP framework calling templates is very simple and powerful. It has its own rules

1. Templates are placed in the view directory

2. A controller corresponds to a folder, and a method corresponds to a page

1.11.2 Calling templates

$this->display();

1.11.3 Assigning values ​​to variables in the controller

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

 $this->sex='male'; //The second method

1.11.4 in the template Value in

 {$name}

1.12 Project Grouping

 A project is divided into at least two groups, one frontend and one backend, each group has its own MVC. When the TP framework automatically generates the project structure, it will automatically generate a front-end group.

Create a new Admin folder (backend folder) in the same directory as Home, and create your own MVC in the folder

1.13 System Constants

__SELF__ : Current Requested address

__MODEL__: current module

__CONTROLLER__: current controller

__ACTION__: current method

get_defined_constants(true) displays all constants, true Indicates group display.

Question: The __CONTROLLER__ constant is a PHP constant. We found that writing this constant directly in the template can be parsed. Why can PHP constants be output in HTML templates? Define a constant NAME in PHP, how to output the value of NAME in the template?

Add a string replacement in the templateContentReplace() method of the ContentReplaceBehavior.class.php file

1.14 Display log information at the bottom of the page

'SHOW_PAGE_TRACE' => true //Display log information at the bottom of the page

After configuration, a small green icon will appear in the lower right corner of the page

1.15 TP production and development mode

define('APP_DEBUG ', TRUE); //Development mode

define('APP_DEBUG', false); //Production mode

1.15.1 Development mode

1. Error prompt comparison Friendly

 2. Code modifications will show effects immediately

 3. Low execution efficiency

1.16.2 Generation mode

 1. The error message is relatively vague

2. Many core code files will be made into a cache file (common~runtime.php), so that requests that originally required loading many files now only need to load one file. Saves a lot of opening and closing overhead.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1088265.htmlTechArticleThinkPHP Framework 1, ThinkPHP Framework 1.1 The concept of the framework The framework is actually a collection of reusable code, and the code of the framework is the framework Architecture code, not business logic code, framework code ensures...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Nov 22, 2023 pm 12:01 PM

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

How is the performance of thinkphp? How is the performance of thinkphp? Apr 09, 2024 pm 05:24 PM

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

ThinkPHP6 backend management system development: realizing backend functions ThinkPHP6 backend management system development: realizing backend functions Aug 27, 2023 am 11:55 AM

ThinkPHP6 backend management system development: Implementing backend functions Introduction: With the continuous development of Internet technology and market demand, more and more enterprises and organizations need an efficient, safe, and flexible backend management system to manage business data and conduct operational management. This article will use the ThinkPHP6 framework to demonstrate through examples how to develop a simple but practical backend management system, including basic functions such as permission control, data addition, deletion, modification and query. Environment preparation Before starting, we need to install PHP, MySQL, Com

See all articles