cp frontend/ api -r
php
第二步複製api初始化模板
webcp -a environments/dev/frontend environments/dev/api
cp -a environments/prod/frontend environments/prod/api
第三步添加api初始化代碼,在根目錄下/environments/index.php
return [
bootstrap
'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
],
],
];
第四步初始化模板
vimphp init
vim /api/config/main.php
全部frontend 換成新增模塊名 api
第五步給api添加別名,在根目錄下/common/config/bootstrap.php
apiYii::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 api
第六步修改api配置文件,在根目錄下/api/config/main.php
frontendvim /api/assets/AppAsset.php
namespace frontend\assets; => namespace api\assets;
vim /api/config/main.php
全部frontend 換成新增模塊名 api