Yii2 add a new directory structure

Source: Internet
Author: User


Build a new directory structure click here for details

Build a restful API click here

1. Development environment
Operating systems Windows Server R2 Datacenter
PHP architecture Apache version UPUPW PHP5.4
Programming software Zend Studio 12.0.2

2. Environment configuration
Unzip the UPUPW to the D packing directory, add three new sites in the UPUPW respectively, as follows
Http://admin.mxq.com
Http://www.mxq.com
Http://api.mxq.com
The site directory uses the default path, and then modifies the D:\upupw\Apache2\conf\httpd-vhosts.conf file, for example
Modify Http://admin.mxq.com's documentroot to D:/upupw/vhosts/mxq.com/backend/web,php_admin_value Open_basedir Modify to D:\ Upupw\vhosts\mxq.com\,directory modified to D:/upupw/vhosts/mxq.com/backend/web, other sites also make corresponding changes

3. Installing Yii from an archive file

    • 3.1 Download the advanced archive from yiiframework.com. Unzip the downloaded file into the D:\upupw\vhosts\mxq.com directory.
    • 3.2 Adding Php.exe to System environment variables
      • ① Right-click My Computer-Properties-advanced-environment variables
      • ② Find path This item (may need to scroll down to find), the mouse double-click Path this item, in the end to add your PHP directory and class library where the path, including the previous ";" (For example:; C:\php; C:\php\ext)
      • ③ Click on the "New" button and enter "PHPRC" in "Variable name", enter the directory where the php.ini file is located in variable value (for example: C:\php), this step is to let Windows find php.ini.
    • 3.3 Run cmd into the installation directory, execute init or run Init.bat in the installation directory, select 0 Development mode for installation
    • 3.4 Add local domain name resolution in UPUPW so that it can be accessed through http://admin.mxq.com, the other two are similar.



4. Add a new app API
Newly deployed Yii only backend and frontend, we add API app manually

    • 4.1 Copy all files under Frontend to API folder, bulk replace Frontend as API
    • 4.2 Open D:\upupw\vhosts\mxq.com\common\config\bootstrap.php, copy the line containing the frontend, and change the Frontend to API to add aliases to the app.
    • 4.3 Opening D:\upupw\vhosts\mxq.com\environments\ index.php, copy the rows containing the frontend, and change the setwritable and Setcookievalidationkey under Api,development and production to copy and modify accordingly.
    • 4.4 Copy the frontend under the D:\upupw\vhosts\mxq.com\environments\dev and D:\upupw\vhosts\mxq.com\environments\prod folders to the same directory, Renamed to API
    • 4.5 Perform the 3.3 operation to access the newly added app via http://api.mxq.com



5. Adding a database table prefix
Open D:\upupw\vhosts\mxq.com\common\config\main-local.php,
Add Children in db

    1. ' Tableprefix ' = ' mxq_ ',
Copy Code



6. Configure the GII to add IP addresses that allow extranet access
Open the D:\upupw\vhosts\mxq.com\backend\config\main-local.php and

$config [' Modules '] [' gii '] = ' yii\gii\module ';

Copy Code

Comment out the line, instead

$config [' Modules '] [' gii '] = [

' Class ' = ' Yii\gii\module ',

' Allowedips ' = [' 127.0.0.1 ', ' 192.168.0.* ']

];

192.168.0.* for your IP address
The init initialization of the development phase will overwrite it, so we modify the D:\upupw\vhosts\mxq.com\environments\dev\backend\config\ directly Main-local.php, other applications are modified as well.

7. Turn on internationalization support, source code Chinese and set time zone, character set default UTF-8
Since all applications are in Chinese, we will open the settings in common.
Open D:\upupw\vhosts\mxq.com\common\config\main.php,
Add on the Components line

' Language ' = ' ZH-CN ',//enable internationalization support

' Sourcelanguage ' = ' zh-cn ',//source code in Chinese

' TimeZone ' = ' Asia/shanghai ',//Set time zone



8. Disable the default layout for API Apps
Open D:\upupw\vhosts\mxq.com\api\config\main.php,
Add on the Components line

' Layout ' = False,



9. Remove Address bar URL encoding
Http://yii2/index.php?r=site%2Flogin
Http://yii2/index.php?r=site/login
The above two URLs, that look more clear? Obviously the second one, in order to achieve this effect, can be modified as follows
Opening D:\upupw\vhosts\mxq.com\vendor\yiisoft\yii2\web\UrlManager.php will

$url = "$baseUrl? {$this->routeparam}= ". UrlEncode ($route);

Switch

$url = "$baseUrl? {$this->routeparam}= ". $route;



10. Develop a layout template for the controller
Writing in the Init method

$this->layout = ";

Fill in your layout file name between the quotation marks

11.Apache three apps Common one advanced template configuration

<virtualhost *:80>DocumentRoot"D:/upupw/vhosts/mxq.com/backend/web"ServerName Admin. mxq.com:80serveralias admin ServerAdmin [email protected]. Mxq.com directoryindex index. html index.htm index.phpdefault. PHP app.php U.PHP errorlog logs/admin.mxq.com-error.LogCustomlog Logs/admin.mxq.com-access_%y%m%d.Logcomonvhost php_admin_value Open_basedir"D:\upupw\vhosts\mxq.com\;D: \upupw\memcached\;D: \upupw\phpmyadmin\;D: \upupw\temp\; C:\Windows\Temp\ "<directory"D:/upupw/vhosts/mxq.com/backend/web"> Options followsymlinks allowoverride all Require all granted </Directory> <lo Cationmatch"/(inc)/(. *) $"> AllowOverride None Require all denied </LocationMatch> <locationmatch"/(Attachment|attachments|uploadfiles|avatar)/(. *). (php|php5|phps|asp|asp.net|jsp) $ "> AllowOverride None Require all denied </locationmatch></virtualhost><virtualhost *:80> DocumentRoot"D:/upupw/vhosts/mxq.com/frontend/web"ServerName www.mxq.com:80 serveralias www ServerAdmin [email protected] DirectoryIndex in dex.html index.htm index.php default.php app.php u.php errorlog logs/www.mxq.com-error.log CustomLog logs/ww W.mxq.com-access_%y%m%d.log comonvhost php_admin_value Open_basedir"D:\upupw\vhosts\mxq.com\;D: \upupw\memcached\;D: \upupw\phpmyadmin\;D: \upupw\temp\; C:\Windows\Temp\ "<directory"D:/upupw/vhosts/mxq.com/frontend/web"> Options followsymlinks allowoverride all Require all granted </Directory> <lo Cationmatch"/(inc)/(. *) $"> AllowOverride None Require all denied </LocationMatch> <locationmatch"/(Attachment|attachments|uploadfiles|avatar)/(. *). (php|php5|phps|asp|asp.net|jsp) $ "> AllowOverride None Require all denied </locationmatch></virtualhost><virtualhost *:80> DocumentRoot"D:/upupw/vhosts/mxq.com/api/web"ServerName api.mxq.com:80 serveralias API ServerAdmin [email protected] DirectoryIndex in dex.html index.htm index.php default.php app.php u.php errorlog logs/api.mxq.com-error.log CustomLog Logs/ap I.mxq.com-access_%y%m%d.log comonvhost php_admin_value Open_basedir"D:\upupw\vhosts\mxq.com\;D: \upupw\memcached\;D: \upupw\phpmyadmin\;D: \upupw\temp\; C:\Windows\Temp\ "<directory"D:/upupw/vhosts/mxq.com/api/web"> Options followsymlinks allowoverride all Require all granted </Directory> <lo Cationmatch"/(inc)/(. *) $"> AllowOverride None Require all denied </LocationMatch> <locationmatch"/(Attachment|attachments|uploadfiles|avatar)/(. *). (php|php5|phps|asp|asp.net|jsp) $ "> AllowOverride None Require all denied </LocationMatch></VirtualHost>

Yii2 add a new directory structure

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.