YII2.0 高級模板-添加自定義模板

第一步進入高級模板根目錄,複製backend更名爲api

cp frontend/ api -r
 php

第二步複製api初始化模板

cp -a environments/dev/frontend environments/dev/api
cp -a environments/prod/frontend environments/prod/api
web

第三步添加api初始化代碼,在根目錄下/environments/index.php



return [
'Development' => [
'path' => 'dev',
'setWritable' => [
'backend/runtime',
'backend/web/assets',
'frontend/runtime',
'frontend/web/assets',
'api/runtime',//add api
'api/web/assets',//add api
],
'setExecutable' => [
'yii',
'tests/codeception/bin/yii',
],
'setCookieValidationKey' => [
'backend/config/main-local.php',
'frontend/config/main-local.php',
'api/config/main-local.php',//add api
],
],
'Production' => [
'path' => 'prod',
'setWritable' => [
'backend/runtime',
'backend/web/assets',
'frontend/runtime',
'frontend/web/assets',
'api/runtime',//add api
'api/web/assets',//add api
],
'setExecutable' => [
'yii',
],
'setCookieValidationKey' => [
'backend/config/main-local.php',
'frontend/config/main-local.php',
'api/config/main-local.php',//add api
],
],
];
bootstrap

第四步初始化模板

php init

vim /api/config/main.php
全部frontend 換成新增模塊名 api  
vim

第五步給api添加別名,在根目錄下/common/config/bootstrap.php

Yii::setAlias('@common', dirname(__DIR__));Yii::setAlias('@frontend', dirname(dirname(__DIR__)) . '/frontend');Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend');Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console');Yii::setAlias('@api', dirname(dirname(__DIR__)) . '/api'); //add apiapi

第六步修改api配置文件,在根目錄下/api/config/main.php

vim /api/assets/AppAsset.php 
namespace frontend\assets; => namespace api\assets;

vim /api/config/main.php
全部frontend 換成新增模塊名 api  
frontend

相關文章
相關標籤/搜索