Download Yii2 with composer is too slow, so I still like to download the packaged framework file.
In https://github.com/yiisoft/yii2/releases Download the latest yii2,advanced is the advanced template, basic is the base template. Their difference is that the advanced template helps you to separate the front and rear modules, and there is only one module in the base template.
Take the advanced template as an example:
Download and extract the files inside the D:\wamp\www\yii2advanced (note: I am the compressed package in the Advanced folder files extracted here, rather than the Advanced folder extracted here).
Then double-click Init.bat to initialize (if you are using the base template without this step), enter the number 0 and return to select development mode, enter Yes and return to OK.
Finally import the sample data (this step can be omitted if you are not going to learn or experience YII2 but want to develop it). First you need to create a database, I name it yii2advanced (Note: Sort suggestions select utf8_general_ci). Under the D:\wamp\www\yii2advanced\common\config directory, Open the main-local.php file, change the dbname inside to your database name, username your database user name, password your database password. Then in the Yii2 root directory, which is my yii2advanced folder, use the cmd command to enter the file directory, input Yii migrate and enter, and then input yes OK, and finally show migrated up successfully. Indicates that the import data was successful.
This allows the YII2 advanced template to be installed and you can access the site from the http://localhost/yii2advanced/frontend/web/front desk:
To access the site from http://localhost/yii2advanced/backend/web/:
Then you can find from the link, whether it is the front desk or backstage, the link is more than a/web/, we want to access the directory should be: The front desk is http://localhost/yii2advanced, backstage for http://localhost/ yii2advanced/admin.php. So let's make the changes now.
It is also clear that the changes should be limited to the module itself and should not modify the YII2 framework.
Let's modify the foreground (in order to avoid the BOM head effect, it is recommended to modify in the IDE):
Open the D:\wamp\www\yii2advanced\frontend\web folder and copy (or cut) the index.php file inside to the root directory D:\wamp\www\yii2advanced. Then edit the contents as follows:
123456789101112131415161718 |
<?php
defined(
‘YII_DEBUG‘
)
or define(
‘YII_DEBUG‘
, true);
defined(
‘YII_ENV‘
)
or define(
‘YII_ENV‘
,
‘dev‘
);
require
(__DIR__ .
‘./vendor/autoload.php‘
);
require
(__DIR__ .
‘./vendor/yiisoft/yii2/Yii.php‘
);
require
(__DIR__ .
‘./common/config/bootstrap.php‘
);
require
(__DIR__ .
‘./frontend/config/bootstrap.php‘
);
$config = yii\helpers\ArrayHelper::merge(
require
(__DIR__ .
‘./common/config/main.php‘
),
require
(__DIR__ .
‘./common/config/main-local.php‘
),
require
(__DIR__ .
‘./frontend/config/main.php‘
),
require
(__DIR__ .
‘./frontend/config/main-local.php‘
)
);
$application =
new yii\web\Application(
$config
);
$application
->run();
|
Then modify the main.php file in the D:\wamp\www\yii2advanced\frontend\config and add it to the component.
1234 |
‘assetManager‘ => [ ‘basePath‘ => ‘@webroot/frontend/web/assets‘ , ‘baseUrl‘ => ‘@web/frontend/web/assets‘ ], |
The whole main.php should be:
12345678910111213141516171819202122232425262728293031323334353637 |
<?php
$params =
array_merge
(
require
(__DIR__ .
‘/../../common/config/params.php‘
),
require
(__DIR__ .
‘/../../common/config/params-local.php‘
),
require
(__DIR__ .
‘/params.php‘
),
require
(__DIR__ .
‘/params-local.php‘
)
);
return [
‘id‘ =>
‘app-frontend‘
,
‘basePath‘ => dirname(__DIR__),
‘bootstrap‘ => [
‘log‘
],
‘controllerNamespace‘ =>
‘frontend\controllers‘
,
‘components‘ => [
‘assetManager‘ => [
‘basePath‘ =>
‘@webroot/frontend/web/assets‘
,
‘baseUrl‘ =>
‘@web/frontend/web/assets‘
],
‘user‘ => [
‘identityClass‘ =>
‘common\models\User‘
,
‘enableAutoLogin‘ => true,
],
‘log‘ => [
‘traceLevel‘ => YII_DEBUG ? 3 : 0,
‘targets‘ => [
[
‘class‘ =>
‘yii\log\FileTarget‘
,
‘levels‘ => [
‘error‘
,
‘warning‘
],
],
],
],
‘errorHandler‘ => [
‘errorAction‘ =>
‘site/error‘
,
],
],
‘params‘ =>
$params
,
];
|
Finally, modify the D:\wamp\www\yii2advanced\frontend\assets in the appasset.php file, will be inside the:
123456789 |
public $css = [ ‘css/site.css‘ , ]; //修改为: public $css = [ ‘frontend/web/css/site.css‘ , ]; |
This allows direct access to the home page with http://localhost/yii2advanced.
The background modification method is to D:\wamp\www\yii2advanced\backend\web index.php folder is copied (cut) to the root directory and renamed to admin.php, the other modifications are similar to the above, just change the frontend to backend.
Original address: http://pandaju.me/article/177 in the original Assetmanger name is wrong, is Assetmanager
Phpcomposer knowledge can be viewed in the Chinese version of the http://www.phpcomposer.com/
Yii2 install and move the portal file to the root directory