访问控制器操作时未找到 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;