【问题标题】:Error 404 Unable to resolve the request in Yii (checked other solution but not work)错误 404 无法解析 Yii 中的请求(检查了其他解决方案但不起作用)
【发布时间】:2015-06-13 18:33:36
【问题描述】:

我收到了这个错误:

Error 404 Unable to resolve the request "PlanComment/update".

它在本地运行良好,但在服务器上运行不正常。 我还更改了区分大小写,但仍然无法正常工作。 这是我的代码:

PlanCommentController.php

类 PlanCommentController 扩展控制器 { /** * @var string 视图的默认布局。默认为'//layouts/column2',意思是 * 使用两列布局。请参阅“受保护/视图/布局/column2.php”。 */ public $layout='//layouts/column2';
/**
 * @return array action filters
 */
public function filters()
{
    return array(
        'accessControl', // perform access control for CRUD operations
       //   'postOnly + delete', // we only allow deletion via POST request
    );
}

/**
 * Specifies the access control rules.
 * This method is used by the 'accessControl' filter.
 * @return array access control rules
 */
public function accessRules()
{
    return array(
        array('allow', // allow authenticated user to perform 'create' and 'update' actions
            'actions'=>array('update', 'delete'),
            'users'=>array('@'),
        ),
        array('allow', // allow admin user to perform 'admin' and 'delete' actions
            'actions'=>array('delete'),
            'users'=>array('admin'),
        ),
        array('deny',  // deny all users
            'users'=>array('*'),
        ),
    );
}

....

查看文件:_comment.php

    $this->widget('booster.widgets.TbButtonGroup', array(
                          'htmlOptions' => array('class' => 'dropup'),
                          'buttons' => array(
                                array('items' => array(
                                    array('label' => 'Delete Comment', 'url' => array('PlanComment/delete',            'id'=>$comment->id, 'plan_id'=>$comment->plan_id),
                                           'visible'=>(Yii::app()->user->id == $comment->user_id) ||   Yii::app()->user->isPlanAuthor($comment->plan_id)),
                                    '---',
                                    array('label' => 'Edit Comment', 'url' => array('PlanComment/update', 'id'=>$comment->id, 'plan_id'=>$comment->plan_id),
                                            'visible'=>(Yii::app()->user->id == $comment->user_id)),
                      )),),)); ?>

配置文件:main.php

// 取消注释以下以启用路径格式的 URL 'urlManager'=>数组( 'urlFormat'=>'路径', // 删除 index.php 'showScriptName'=>假, '大小写敏感'=>假, '规则'=>数组( '家'=>'网站/索引', '计划'=>'计划/索引', '视频'=>'视频/索引', '登录/' => '网站/登录' , '' => 'site/', '/_'=>'/view', '/update/_'=>'/update', '/view_thanhvien/_'=>'/view_thanhvien', '//'=>'/', '/'=>'/', ), ),

我的代码哪里出错了? 请帮忙。

【问题讨论】:

  • 查看我的回答here。通常,除了控制器名称的第一个字母和“Controller”中的“C”之外,您希望避免在控制器名称中出现多个大写字母。
  • 我在下面尝试了一些方法但仍然不起作用: 1. PlancommentController.php class PlancommentController extends Controller 'url' => array('Plancomment/delete', --------- --- 2. plancommentController.php 类 plancommentController 扩展控制器 'url' => array('plancomment/delete', ----------- 3. PlancommentController.php 类 PlancommentController 扩展控制器 'url' =>数组('计划注释/删除',
  • 哦,是的。现在可以了。谢谢 M 索斯特。我关于 git commit 的错误任务。在以下情况下工作:PlancommentController.php;类 PlancommentController 扩展控制器; 'url' => array('plancomment/delete',

标签: php yii


【解决方案1】:

您的网址应该是 "planComment/update" 而不是 "PlanComment/update". 控制器名称的首字母必须小写

【讨论】:

  • 我认为问题在于您的 url-manager 规则。尝试始终使用我的建议(因为这是一个很好的做法)。接下来尝试删除所有 url-manager 规则(默认规则除外)。如果问题解决了,您可以更改您的 url-manager 规则。
  • 谢谢@hamed。我尝试了 M Sost 的建议。现在效果很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-13
  • 1970-01-01
  • 2019-12-03
  • 2019-06-13
  • 1970-01-01
相关资源
最近更新 更多