yii2中的controllermap返回404

时间:2016-08-30 14:40:20

标签: yii yii2 yii2-basic-app

我在manual

中复制此代码,然后在yii2手册中走动
    'controllerMap' => [
        'account' => 'yii\app\controllers\UserController',
        'article' => [
            'class' => 'yii\app\controllers\PostController',
            'enableCsrfValidation' => false,
        ],
],

在netbean中粘贴

enter image description here

只是访问它

enter image description here

已经有UserController enter image description here

1 个答案:

答案 0 :(得分:0)

你的命名空间错了!如果你看文档,正确的代码是这样的:

[
    'controllerMap' => [
        'account' => 'app\controllers\UserController',
        'article' => [
            'class' => 'app\controllers\PostController',
            'enableCsrfValidation' => false,
        ],
    ],
]

但是,在命名空间的开头有一个额外的yii,因此yii\app\controllers\UserController必须是app\controllers\UserController

另外我认为你在网址重写方面遇到了一些问题。如果我是真的,你可以在http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html#using-pretty-urlsyii2 url rewrite config找到一种修复它的工具。