背景是这样的,最开始开发的时候没有做restful和版本控制
控制器在frontend/controllers/
模型frontend/models/
现在想新开发的功能开始用restful 和 版本控制
并且能将以前的也兼容到restful里
求一份配置文件
$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',
'controllerNamespace' => 'frontend\common\controllers',
'modules' => [
'v1' => [
'basePath' => '@frontend/modules/v1',
],
'v2' => [
'basePath' => '@frontend/modules/v2',
],
],
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => ['user', 'user']],
['class' => 'yii\rest\UrlRule', 'controller' => ['v1/test', 'v1/post']],
['class' => 'yii\rest\UrlRule', 'controller' => ['v2/test', 'v2/post']],
],
],
'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,
];
我是克隆了frontend对应的配置,然后将main.php改成这样子的:
粗体