gpt4 book ai didi

访问 Controller 操作时未找到 yii2 url

转载 作者:行者123 更新时间:2023-12-05 00:22:17 28 4
gpt4 key购买 nike

我创建了一个 Controller 功能,如

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 是 Controller 的名字(TicketController.php)) 它显示 Not Found (#404)错误。

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

我的 Controller 是这样的

<?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 是

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/web/ticket/rateticket/2333价票 .

关于访问 Controller 操作时未找到 yii2 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30163778/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com