我创建了一个像
这样的控制器功能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的网络文件夹是
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
答案 0 :(得分:3)
更改actionRateticket
的操作名称,并且通过 rateticket 调用http://mydomainname/web/ticket/rateticket/2333。
答案 1 :(得分:3)
尝试使用以下行:
persist
答案 2 :(得分:0)
您需要在访问行为中指定操作
'access' => [
'class' => AccessControl::className(),
'only' => ['rate-ticket', 'index','view','update','delete','newticket' ],
'rules' => [
[
'actions' => ['rate-ticket', 'index','view','update','delete','newticket', ],
'allow' => true,
'roles' => ['@'],
],
],
],
答案 3 :(得分:0)
我相信这是因为Yii使用破折号代替骆驼案的奇怪方式。尝试将规则从<action:\w+>
更改为<action:[-\w]+>
,因为短划线不是单词字符!
我无法找到默认规则来验证他们是否也会检查短划线,但这应该有效。
答案 4 :(得分:0)
yii2使用更多SEO友好网址为骆驼案件控制器。所有驼峰的情况都用这样的破折号转换成小写:
UserProfileController
index.php?r=user-profile