簡體   English   中英

Yii2中的路線不起作用

[英]Route in Yii2 doesn't work

我無法向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時 ,出現了相同的錯誤

怎么了?

它應該是:

  1. http://account.li/index/index或僅http://account.li/index (因為index是默認操作)。 如果默認控制器是IndexController中,你可以像訪問- http://account.li/
  2. http://account.li/index/create-account

實際網址中的控制器和動作名稱應使用小寫字母。 包含多個單詞的動作名稱在單詞之間用連字符進行轉換。

嘗試改變

public function actionCreateAccount()

public function actionCreateaccount()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM