簡體   English   中英

訪問控制器操作時未顯示yii2 url

[英]yii2 url not found shown while accessing controller action

我已經創建了一個控制器功能

public function actionRateTicket($id){

}

urlManager具有以下配置

'urlManager' => [
            'class' => 'yii\web\UrlManager',
            // Disable index.php
            'showScriptName' => false,
            // Disable r= routes
            'enablePrettyUrl' => true,'enableStrictParsing' => true,

            'rules' => array(
                    '<controller:\w+>/<id:\d+>'              => '<controller>/view',
                    '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                    '<controller:\w+>/<action:\w+>'          => '<controller>/<action>',
            ),
        ],

但是當我嘗試訪問http:// mydomainname / web / ticket / rate-ticket / 2333時 ,(ticket是控制器的名稱(TicketController.php))它顯示Not Found (#404)錯誤。

這里有什么問題? 我可以使用單個駝峰大小寫字符來訪問所有控制器操作,例如actionView,actionEdit等,但是actionRateTicket,我無法訪問。 如果actionRateTicket重命名為actionRate,則它正在運行。

我的控制器是這樣的

<?php

namespace app\controllers;

use Yii;
use app\models\Techs;
use app\models\Ticket;
use app\models\Assignment;
use app\models\TicketSearch;
use app\models\ComplainType;
use app\models\TicketComplain;
use app\models\User;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use app\models\Adusers;
use yii\web\UploadedFile;
use app\helpers\Utils;
use yii\db\Expression;
use yii\filters\AccessControl;


/**
 * TicketController implements the CRUD actions for Ticket model.
 */
class TicketController extends Controller {
    public function behaviors() {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only'  => [
                    'index', 
                    'view',
                    'update',
                    'delete', 
                    'newticket'
                ],
                'rules' => [
                    [
                        'actions' => [
                            'index',
                            'view', 
                            'update',
                            'delete', 
                            'newticket'
                        ],
                        'allow'   => true,
                        'roles'   => ['@'],
                    ],
                ],
            ],
            'verbs'  => [
                'class'   => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }

    public function actionRateTicket($id) {
        echo "in"; echo $id;
        exit;
    }
}
?>

我的.htaccess的web文件夾是

RewriteEngine on

# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php

改變的動作名稱actionRateticket ,呼叫應該是HTTP:// mydomainname /網絡/票/ rateticket / 2333rateticket。

嘗試使用以下行:

use yii\helpers\Url;

您需要在訪問行為中指定操作

'access' => [
                    'class' => AccessControl::className(),
                    'only' => ['rate-ticket', 'index','view','update','delete','newticket' ],
                    'rules' => [
                            [
                                    'actions' => ['rate-ticket', 'index','view','update','delete','newticket', ],
                                    'allow' => true,
                                    'roles' => ['@'],
                            ],

                    ],
            ],

我相信這是因為Yii使用破折號而非駱駝案的奇怪方式。 嘗試將規則從<action:\\w+>更改為<action:[-\\w]+>因為短划線不是單詞字符!

我找不到默認規則來驗證他們是否也檢查了破折號,但這應該有效。

yii2使用更多的SEO友好網址為駱駝案件控制器。 所有駝峰案例都轉換為小寫字母,如下所示:

UserProfileController
index.php?r=user-profile

暫無
暫無

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

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