Yii2.0 Authoritative Guide

Source: Internet
Author: User

Yii is a high-performance, component-based PHP framework for rapid development of WEB applications.

First, installation
1.Composer Installation
Composer is a project-based dependency manager that installs the packages or libraries that the PHP project relies on in the directory where the project resides
Curl-ss Https://getcomposer.org/installer | Php
MV Composer.phar/usr/local/bin/composer

2. Installing Yii
Installing the Composer Asset Plugin package management plug-in
Composer global require "fxp/composer-asset-plugin:~1.0.0"
Install Yii into a directory called basic
Composer Create-project--prefer-dist Yiisoft/yii2-app-basic basic
Note: Your GitHub identity token token will be asked during the installation process, and you can generate tokens in GitHub settings and copy them here.

Copy the basic project folder to the Web server root directory (/var/www/html) and access the address http://localhost/basic/web/index.php
The following interface appears, indicating that the installation was successful.

Second: Yii Request processing process

The most important directories and files in your app (assuming the app root is basic):

basic/Application root directory
Composer.json composer configuration file, describing package information
config/includes application configuration and other configurations
console.php Console Application configuration information
web.php Web App configuration information
commands/contains console command classes
Controllers/contains the Controller class
models/contains model classes
runtime/contains files generated by YII at run time, such as logs and cache files
The vendor/contains the installed Composer package, including the YII framework itself
views/contains view files
Web/web application root directory, including Web portal files
Assets/contains resource files for Yii publishing (JavaScript and CSS)
index.php Application Portal File
Yii yii console Command execution script

YII implements the model-view-controller (MVC) design pattern. The models directory contains all the model classes, and the views directory contains all the view scripts, and the Controllers directory contains all the controller classes.


The table shows the static structure of an application:

Each app has a portal script, web/index.php, which is the only PHP script that can be accessed throughout the app. The portal script accepts a WEB request and creates an application instance to handle it. The application parses the request with its build assist and dispatches the request to the MVC element. The view uses widgets to create complex and dynamic user interfaces.

Request Life cycle

The table shows how an app handles requests:

1. The user initiates the request to the portal script web/index.php.
2. The portal script loads the application configuration and creates an application instance to process the request.
3. Apply the route through the request component to resolve the request.
4. The application creates a controller instance to process the request.
5. The controller creates an action instance and executes the filter against the action.
6. If any one of the filters fails to return, the operation exits.
7. If all filters are passed, the operation will be performed.
8. The operation will load a data model, perhaps from a database.
9. The operation renders a view that provides the data model to it.
10. The render result is returned to the response component.
11. The response component sends the render result to the user's browser.

Reference: http://www.yiichina.com/doc/guide/2.0

Yii2.0 Authoritative Guide

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.