YII2 framework (6) advanced application template from scratch, yii2 framework _ PHP Tutorial

Source: Internet
Author: User
Learn YII2 framework (6) advanced application template from scratch, yii2 framework. Learn YII2 framework (6) advanced application templates from scratch. yii2 framework advanced application templates are used in large-scale Team development projects, in addition, the background is separated from the foreground to learn the YII2 framework (6) advanced application template from the beginning, and the yii2 framework

Advanced Application Template
This template is used in large-scale Team development projects, and the background is isolated from the foreground for ease of deployment on multiple servers. Due to some new features of YIi2.0, the functions of this program template are more advanced. Provides basic database support, registration, password retrieval, and other functions.

Install

You can use Composer to install
If you have not installed Composer, first install

curl -s http://getcomposer.org/installer | php

Run the following command to obtain

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

You can also download the compressed file: Yii 2 with advanced application template (beta)
Https://github.com/yiisoft/yii2/... app-2.0.0-beta.tgz

Start

After the installation is complete, you need to initialize it.

Run init, select the development environment (dev) php/path/to/yii-application/init to create a new database, set the components in the common/config/main-local.php. database information use console commands to migrate database yii migrate settings web server root directory foreground/path/to/yii-application/frontend/web/corresponding url is http: // frontend/backend/path/to/yii-application/backend/web/the corresponding url is http: // backend/

Directory structure

There are several subdirectories under the root directory.

Backend -- background web programs
Common -- public file
Console-console program
Environments -- environment configuration
Frontend-front-end web programs
The root directory contains some files.

. Gitignore-files and directories ignored in git version control. if you have files you don't want to add to your source code, add them to the file.
Composer. json -- this is described below
Init -- initialization script described in Composer
Init. bat -- the same as above, but
LIENSE. md -- leave it alone.
README. md -- same as above
Requirements. php -- Yii runtime environment requirements file detection
Yii -- Console program Boot File
Yii. bat -- Windows stuff

Path alias defined by the system

@ Yii -- framework directory.
@ App -- basic path of the currently running application.
@ Common-public file directory.
@ Frontend -- Front-end web application directory.
@ Backend -- directory of the backend web application.
@ Console-console directory.
@ Runtime -- runtime Directory of the currently running web application
@ Vendor-basic framework directory.
@ Web -- the url of the currently running web application
@ Webroot-the web root directory of the currently running web application.

Applications

This template contains three applications: foreground, background, and console. The foreground is usually displayed to end users, that is, the project itself. The background is the administrator control panel, which includes analysis and similar functions. The console is mainly used to perform some scheduled tasks and manage some simple servers. It can also be used to deploy applications, migrate databases, and manage resources.

The common directory provides some public files for multiple applications, such as the User model.

Both the front-end and back-end are web applications. they all contain a web directory, that is, the web root directory, which must be directed to when deploying servers.
Each application has its own namespace and corresponding alias. Similarly, common has its own namespace and corresponding alias.

Configuration and development environment

In normal development, directly setting the configuration file may cause multiple problems.

Each team member has their own configuration options. If such a configuration is submitted, other team members will be affected.
The product database password and API key should not be in the code repository.
When there are multiple servers: development, testing, and production, each server should have its own configuration.
In each case, all configuration options are defined to be repeated and it takes too much time to maintain them.

To solve these problems, Yii introduces a very simple concept of environment. Each environment is represented by a set of files in the environment directory. The init command is used for switching between different environments. It only copies the root directory of all applications from the environment directory.

The environment usually contains the app boot files such as index. php and configuration files suffixed with-local. php. These have been added to. gitignore, so they will not be added to the source code repository.
To prevent duplicate configuration files from overwriting each other. For example, the foreground application reads the configuration in the following order:

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

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 read later will overwrite the previous configuration.

The entire process is shown as follows:

Configure Composer

After the application is installed, you can set composer. json under the Directory

{  "name": "yiisoft/yii2-app-advanced",  "description": "Yii 2 Advanced Application Template",  "keywords": ["yii", "framework", "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.yiiframework.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/yii2": "*",    "yiisoft/yii2-swiftmailer": "*",    "yiisoft/yii2-bootstrap": "*",    "yiisoft/yii2-debug": "*",    "yiisoft/yii2-gii": "*"  },  "scripts": {    "post-create-project-cmd": [      "yii\\composer\\Installer::setPermission"    ]  },  "extra": {    "writable": [      "backend/runtime",      "backend/web/assets",      "console/runtime",      "console/migrations",      "frontend/runtime",      "frontend/web/assets"    ]  }}

First, modify some basic information. For example, name, description, keyword, and homepage.
You can also add more applications as needed. These packages are all from packagist.org and you can view all the code for free.
After modifying composer. json, you can run

php composer.phar update --prefer-dist

After the download and installation are complete, you can start using it. The automatically loaded class is automatically processed.

Create a link from the backend to the front-end

In general, you need to connect to the front-end application from the back-end application. Because the front-end application may contain its own URL management rules, you need to add another background URL management rule with different names.

return [  'components' => [    'urlManager' => [      // here is your normal backend url manager config    ],    'urlManagerFrontend' => [      // here is your frontend URL manager config    ],  ],];

Then, you can use the foreground url like this.

echo Yii::$app->urlManagerFrontend->createUrl(...);

Http://www.yiiframework.com/doc-2.0/guide-apps-advanced.html
(Yii Framework 2.0 API Decumentation)


You cannot create an application group to learn English from scratch

Find the human. ini file in the C: \ windows \ folder.

Edit file content:

[ZERO]
CDPATH = L: \ here is your virtual drive letter. you can check which disk you want to change.
HDPATH = d: \ Program Files \ HumanSoft \ ZERO \ change your installation path here.
[HumanASR Parameter]
BnfMode = 2
MarkMode = 2
GradeMark = 10
FactorMark = 10

Then open the program in the installation directory.

The app store's "learning English from scratch" is charged and easy to use.

I am not very familiar with what you said. There are many related learning websites, but the learning methods vary from person to person. after you have a detailed understanding, you can determine a learning platform suitable for you.
You can search Baidu for "English coach" for details
1. don't worry about the lack of time. our learning time is flexible and it is up to you;
2. don't worry about being cheated. if you are satisfied with the trial, you can pay for it again. if you are not satisfied, you don't have to spend a penny (of course, you haven't passed the trial yet, but you are not satisfied with our tutorial );
3. Don't worry about lack of foundation. our tutorial will gradually strengthen from scratch and provide special guidance;
4. Don't worry that you cannot keep up with the teaching progress. our learning plan is developed based on individual differences;
5. Don't worry about problems encountered during the learning process and cannot be solved in a timely manner. we will assign a dedicated person for each student to follow up and coach.
 

Middleware (6) advanced application template, yii2 framework advanced application template this template is used in large-scale Team development projects, and the background is independently separated from the foreground...

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.