访问控制器操作时未找到 yii2 url [英] yii2 url not found shown while accessing controller action

查看:59
本文介绍了访问控制器操作时未找到 yii2 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个控制器函数,如

I have created a controller function like

public function actionRateTicket($id){

}

urlManager有如下配置

The urlManager has the following configuration

'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 is the name of controller(TicketController.php)) 它显示 Not Found (#404) 错误.

But when I tried to access http://mydomainname/web/ticket/rate-ticket/2333 , (ticket is the name of controller(TicketController.php)) it is showing Not Found (#404) error.

这里有什么问题?我可以使用单个驼峰字符(如 actionView、actionEdit 等)访问所有控制器操作,但是 actionRateTicket,我无法访问.如果将 actionRateTicket 重命名为 actionRate,则它可以正常工作.

What is the problem here? I am able to access all controller actions with a single camel case characters like actionView, actionEdit etc, but actionRateTicket, I am not able to acess. If the actionRateTicket is renamed to actionRate, it is working.

我的控制器是这样的

<?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;
    }
}
?>

我的 web 文件夹的 .htaccess 是

My .htaccess of web folder is

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

推荐答案

尝试使用以下行:

use yii\helpers\Url;

这篇关于访问控制器操作时未找到 yii2 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆