Learn YII2 framework from scratch (vi) Advanced Application Templates, YII2 framework _php Tutorials

Source: Internet
Author: User
Tags yii

Learn YII2 framework from scratch (vi) Advanced Application templates, YII2 framework

Advanced Application Templates
This template is used in large team development projects, and the background is isolated from the foreground to facilitate deployment across multiple servers. Due to some of the new features of YIi2.0, this program template has a deeper function. Provides basic database support, registration, password retrieval and other functions.


Can be installed via composer.
If composer is not installed, first install

Curl-s Http://getcomposer.org/installer | Php

Then use the following command to get

PHP composer.phar create-project--prefer-dist--stability=dev yiisoft/yii2-app-advanced/path/to/yii-application

You can also download the zip file directly: Yii 2 with Advanced application Template (Beta)


After the installation is complete, it needs to be initialized.

Execute INIT, select development environment (DEV) php/path/to/yii-application/init Create a new database, set common/config/ Components.db database information in main-local.php use the console command to migrate the database Yii migrate set the root directory of the Web server foreground/path/to/yii-application/frontend/web/ The corresponding URL for http://frontend/background/path/to/yii-application/backend/web/corresponds to a URL of http://backend/

Directory structure

There are a few subdirectories underneath the root directory

backend--Background Web Program
common--Public Files
console--Console Program
environments--Environment Configuration
frontend--Foreground Web Program
The root directory also contains some files

Files and directories ignored in the. Gitignore--git version control, if you have some files you do not want into your source code, add it to this file.
composer.json--this will describe below
init--Init script described in composer
init.bat--is the same as above, but under Windows
liense.md--, that's not the word.
REQUIREMENTS.PHP--YII running environment requires inspection files
yii--Console Program boot file
Yii.bat--windows, the following stuff.

System-defined path aliases

@yii-The directory of the framework.
@app-the base path of the application that is currently running.
@common-Public file directory.
@frontend-The front-end Web application directory.
@backend--The back-end Web application directory.
@console-Console directory.
@runtime-The run-time directory of the currently running Web application
@vendor--The base framework directory.
@web-the URL of the currently running Web application
@webroot-the Web root of the Web application that is currently running.


This template contains three applications, foreground, background, and console. The front desk is usually presented to the end user, i.e. the project itself. Backstage is the Administrator control Panel, including analysis and similar functions. The console is mainly used to do some scheduled tasks and some simple server management, also can be used to deploy applications, database migration, resource management and so on.

The common directory provides some common files that can be used in multiple applications, such as the user model.

Both the foreground and the background are Web applications that contain a web directory, the root of the web, that is to be pointed to when the server is deployed.
Each application has its own namespace and the corresponding alias. In the same vein, Common has its own namespace and corresponding aliases.

Configuration and development environment

In normal development, there are multiple issues with setting up a configuration file directly

Each team member has its own configuration options. If you submit such a configuration, it will affect other team members.
The product database password and API key should not be in the code warehouse.
In the case of multiple servers: development, testing, production, each server should have its own configuration.
In each case, it is very repetitive to define all the configuration options, and it takes too much time to maintain it.

To solve these problems, Yii introduces a very simple concept of the environment. Each environment is represented by a collection of a set of files under the environment directory. The init command is used to switch between different environments. It simply replicates the root directory of all applications from the environment directory.

Typically the environment contains application boot files such as index.php and configuration files with the-local.php suffix. These have been added to the. Gitignore, so they are no longer added to the source repository.
In order to avoid duplicate configuration files overwriting each other. For example, the foreground application reads the configuration in the following order:


Parameter files are read in the following order

common/config/params.phpcommon/config/params-local.phpfrontend/config/params.phpfrontend/config/ params-local.php

The file configuration that is read later overrides the previous configuration

The entire flowchart is shaped as follows

Configure Composer

After the application is installed, you can set the Composer.json below the directory

{"Name": "yiisoft/yii2-app-advanced", "description": "Yii 2 Advanced Application Template", "keywords": ["Yii", "frame Work "," Advanced "," Application Template "]," homepage ":" http://www.yiiframework.com/"," type ":" Project "," License ":" Bsd-3-clause "," support ": {" Issues ":" Https://github.com/yiisoft/yii2/issues?state=open "," Forum ":" Http://www.yii framework.com/forum/"," wiki ":" http://www.yiiframework.com/wiki/"," IRC ":" Irc://irc.freenode.net/yii "," source " : "Https://github.com/yiisoft/yii2"}, "minimum-stability": "Dev", "require": {"PHP": ">=5.4.0", "Yiisoft/yii 2 ":" * "," Yiisoft/yii2-swiftmailer ":" * "," yiisoft/yii2-bootstrap ":" * "," yiisoft/yii2-debug ":" * "," yiisoft/y Ii2-gii ":" * "}," scripts ": {" Post-create-project-cmd ": [" Yii\\composer\\installer::setpermission "]}," Extra ": {" writable ": [" Backend/runtime "," Backend/web/assets "," Console/runtime "," Console/migrat Ions "," frontend/ruNtime "," Frontend/web/assets "]}} 

First, modify some basic information. such as name, description, keywords, homepage and so on.
You can also add more applications depending on your needs. These packages are all from packagist.org and are free to browse all the code.
After modifying Composer.json, you can run

PHP Composer.phar Update--prefer-dist

, you can start using it when the download and installation are complete. Automatically loaded classes will be processed automatically.

Create a link from the back end to the front end

Typically, you need to connect to a front-end application from a back-end application. Because the front-end application may contain its own URL management rules, you need to add a URL management rule with a different name in the background.

return [  ' components ' = = [    ' Urlmanager ' + [//] here is      your normal backend URL manager config    ],
   ' urlmanagerfrontend ' = = [      //Here is your frontend URL Manager config    ],]  ;

After that, you can use the foreground URL like this

echo Yii:: $app->urlmanagerfrontend->createurl (...);

Translation Source: http://www.yiiframework.com/doc-2.0/guide-apps-advanced.html
(Yii Framework 2.0 API decumentation)

Learn English from scratch not available to create an application group

Locate the Human.ini file in the C:\windows\ folder.

Edit File Contents:

Cdpath=l:\ Here is your virtual CD drive letter, you can see which disk you are going to change.
Hdpath=d:\program files\humansoft\zero\ here to change your installation path.
[Humanasr Parameter]

You can then open the program in the installation directory.

The "Learn English from scratch" app in the app store charges

For you said that is not very understanding, the relevant learning site a lot, but the learning method varies from person to man, can be detailed understanding, then determine a suitable for their own learning platform
You can search "English instructor" in Baidu for more information
1, do not worry about no time, our study time is flexible, entirely by your own to set;
2, do not worry about being deceived, can try to pay after the satisfaction of the study, not satisfied with not spending a penny (of course, not yet through the trial, not satisfied with our tutorial students);
3, do not worry about no foundation, we tutorial, from zero, gradually strengthen, and have special guidance;
4, do not worry that they can not keep up with the teaching progress, our study plan is based on individual differences to make;
5, do not worry about the learning process encountered problems, can not be resolved in a timely manner, we will assign a person to each trainee, follow-up counseling

http://www.bkjia.com/PHPjc/866653.html www.bkjia.com true http://www.bkjia.com/PHPjc/866653.html techarticle Starting from scratch YII2 Framework (vi) Advanced Application Templates, YII2 framework advanced Application Templates This template is used in large team development projects, and the background is isolated from the foreground independently ...

  • Related Article

    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.