Home > Backend Development > PHP Tutorial > You are a light in the cold night!

You are a light in the cold night!

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:08:03
Original
1098 people have browsed it

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 the business logic code. The framework code protects classes, methods, functions, etc. The framework code is combined according to certain rules to form frame.
1.2 Problems encountered when developing without using a framework
 1. There is no unified standard for code writing
 2. The project functions cannot be divided well
 3. A small local change may affect the overall situation
 4. Upgrading of the project It’s more troublesome
1.3 Benefits of using frameworks
 1. Conducive to a unified coding style for the team
 2. Focus all your energy on business logic without caring about the underlying framework
 3. Build programs quickly, stably and efficiently
 4. Save a lot of code
 5. Later maintenance and upgrades are very convenient
1.5 related frameworks
 1. zendframework: It is officially released by zend (zend company is a company that maintains and upgrades the PHP language). It is very powerful and is a heavyweight framework
 2. Yii: A heavyweight framework developed by Chinese people, this framework maximizes the reusability of code
 3.cakePHP: foreign framework, slow
 4.symfony: foreign framework
 5.CI: (code Igniter), light Magnitude 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 in 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, for use by all projects built on this TP framework
Library: Class library
Library folder under ThinkPHP 1.7.1
Behavior: Framework runtime auxiliary classes
Think: ThinkPHP core code
Vendor: Chapter Some third-party plug-ins
1.7.2 Think folder under ThinkPHPLibrary
Several files to pay attention to:
Controller.class.php: Basic controller
Model.class.php: Basic model
Think.class.php: Every time All requests must be executed with files
  View.class.php: Basic view
1.8 Structure of the framework
  Create a new index.php (entry file) under the site, 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, it supports multiple projects);
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, it will The application folder is 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 + Controller, using Pascal nomenclature
 3. The class name and 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 when creating Controllers namespace and introduce 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:
URL customization function through rewriting Routing can simplify the URL and hide the real path.
 The pseudo-static technology is the rewriting mode.
Required configuration items:
 'URL_ROUTER_ON' => true, //Enable routing
 'URL_ROUTE_RULES' => array(
 'test' => 'home/Goods/test',
), // Routing rules
Redirect transfer parameters
1.11 Definition. Calling templates
1.11.1 Rules
 TP framework calling templates is very simple and powerful. It has some rules of its own
 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 the template
 $this->display();
1.11 .3 Assign values ​​to variables in the controller
  $this->assign('name','tom') //The first method
  $this->sex='male'; //The second method
1.11.4 Get value in template
 {$name}
1.12 Project grouping
A project is divided into at least two groups, one frontend and one backend, and 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__: the address of the current request
 __MODEL__: the current module
 __CONTROLLER__: the current controller
__ACTION__: The current method
get_defined_constants(true) displays all constants, true means 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, it will be displayed on the page A small green icon appears in the lower right corner
1.15 TP production and development mode
define('APP_DEBUG', TRUE); //Development mode
define('APP_DEBUG', false); //Production mode
1.15.1 Development mode
( 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.

The above introduces you as a ray of light in the cold night! , including relevant content, I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
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
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template