Yii2中的路线不起作用

时间:2014-12-09 14:31:17

标签: php yii2

我无法在Yii2中向我的控制器提出请求

我有控制器/controllers/IndexController.php

class IndexController extends Controller
{
    public function actionIndex()
    {
        return $this->render('index');
    }

    public function actionCreateAccount()
    {
        return Json::encode(array('status'=>'ok'));
    }
}

在我的config / web.php

    'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false
    ],

当我尝试提出请求时 http://account.ll/Index/CreateAccount 我收到错误

Unable to resolve the request "Index/CreateAccount".

当我尝试提出请求时 http://account.ll/Index 我收到同样的错误

什么错了?

3 个答案:

答案 0 :(得分:1)

应该是:

  1. http://account.li/index/index或仅http://account.li/index(因为index是默认操作)。如果默认控制器是IndexController,您可以像这样访问它 - http://account.li/
  2. http://account.li/index/create-account
  3. 实际网址中的控制器和操作名称应为小写。包含多个单词的动作名称将在单词之间使用连字符进行转换。

答案 1 :(得分:0)

尝试更改

public function actionCreateAccount()

public function actionCreateaccount()

答案 2 :(得分:0)

相关问题