当我调用特定操作时,上传到主机上的 Yii 应用程序会出现 404 错误 [英] Yii app uploaded on host brings up a 404 error when I call a specific action

查看:32
本文介绍了当我调用特定操作时,上传到主机上的 Yii 应用程序会出现 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 xampp 开发我的应用程序,并且一切正常.但是,当我将它上传到主机(主机)并尝试访问特定页面时,我收到了 404 错误.

将我链接到该页面(来自不同控制器)的按钮将其作为网址:

array('url'=>'Yii::app()->createUrl("symptomHistory/patientSymptomHistory",array("id"=>$data->primaryKey))',

(它是网格视图中的一个按钮)

它调用的动作如下:

公共函数 actionPatientSymptomHistory($id){//创建模型医生请求并在数据库中搜索医生用户和医生之间的医生请求//患者用户$doctorRequestModel = 新医生请求;$doctorPatientRequest = $doctorRequestModel->findByAttributes(array('doctorID'=>Yii::app()->user->id, 'userID'=>$id, 'doctorAccepted'=>1));//如果医生和病人之间有一个接受的医生请求,显示病人的症状历史if(isset($doctorPatientRequest)){$model = 新症状史;//患者数据模型$patientModel = User::model()->findByPk($id);//空数组存储所有用户的症状$symptomItems = array();//查找属于该用户的所有症状历史记录$symptomHistoryModels = $model->findAllByAttributes(array('user_id'=>$id));//遍历属于用户的所有symbolHistory记录foreach($symptomHistoryModels as $symptom){//切换事件颜色的大小写.为每种标志类型设置颜色开关($symptom->symptomFlag){情况1':$symptomColor = '#A1EB86';休息;情况2":$symptomColor = '#CCCA52';休息;案例3":$symptomColor = '#F25138';休息;默认:$symptomColor = '#36c';}//创建事件$symptomItem=array('title'=>$symptom->symptomTitle,'开始'=>$symptom->dateSymptomFirstSeen,'end'=>$symptom->dateSearched,'symptomCode'=>$symptom->symptomCode,'symptomHistoryID'=>$symptom->id,'flag'=>$symptom->symptomFlag,'颜色'=>$symptomColor);//将symbolicHistory事件复制到数组中array_push($symptomItems, $symptomItem);}//呈现患者历史$this->render('patientSymptomHistory',array('模型'=>$model, 'patientModel'=>$patientModel, 'symptomHistoryEvents'=>$symptomItems));}else//否则抛出异常{throw new CHttpException(403, '您无权检查该患者的症状历史');}}

(抱歉代码太长,但老实说,我不知道什么可能有帮助,什么可能没有).

我再说一遍,我收到的是 404 错误,而不是 403 错误.

有谁知道为什么我会收到这个错误?谢谢你的帮助:)

解决方案

这类似于这里的这个问题:Yii 1.14 控制器从模块中的两个部分产生 404 错误

由于控制器的命名约定,环境之间的差异可能导致这种性质的 404.由于大写和小写字符具有不同的 ASCII 值,因此某些环境会对它们进行不同的评估.

根据我的经验,按照以下模式命名控制器:FooController.php,其中 Controller 中的第一个字母和C"大写,没有其他任何内容,似乎适用于所有环境.>

I am developing my app using xampp, and everything works fine there. But when I upload it on a host (hostinger) and try accessing a specific page I get a 404 error.

The button linking me to that page (from a different controller) has this as a url:

array('url'=>'Yii::app()->createUrl("symptomHistory/patientSymptomHistory",array("id"=>$data->primaryKey))',

(it's a button in a gridview)

The action that it calls is the following:

public function actionPatientSymptomHistory($id)
{
    //create model doctor request and search the database for a doctor request between the doctor user and 
    //the patient user
    $doctorRequestModel = new DoctorRequests;
    $doctorPatientRequest = $doctorRequestModel->findByAttributes(array('doctorID'=>Yii::app()->user->id, 'userID'=>$id, 'doctorAccepted'=>1));
    //if there is an accepted doctor request between doctor and patient, show the patients's symptom history
    if(isset($doctorPatientRequest))
    {   
        $model = new Symptomhistory;


        //model for the patients data
        $patientModel = User::model()->findByPk($id);
        //empty array to store all the user's symptoms
        $symptomItems = array();
        //find all symptomHistory records belonging to the user
        $symptomHistoryModels = $model->findAllByAttributes(array('user_id'=>$id));
        //loop through all the symptomHistory records that belong to the user
        foreach($symptomHistoryModels as $symptom)
        {
            //switch case for event color. set color for each flag type
            switch($symptom->symptomFlag)
            {
                case '1':
                    $symptomColor = '#A1EB86';
                    break;
                case '2':
                    $symptomColor = '#CCCA52';
                    break;
                case '3':
                    $symptomColor = '#F25138';
                    break;
                default:
                    $symptomColor = '#36c';
            }
            //create event
            $symptomItem=array('title'=>$symptom->symptomTitle,
                                'start'=>$symptom->dateSymptomFirstSeen,
                                'end'=>$symptom->dateSearched,
                                'symptomCode'=>$symptom->symptomCode,
                                'symptomHistoryID'=>$symptom->id,
                                'flag'=>$symptom->symptomFlag,
                                'color'=>$symptomColor
            );
            //copy symptomHistory event into array
            array_push($symptomItems, $symptomItem);
        }
        //render patient history
        $this->render('patientSymptomHistory',array(
            'model'=> $model, 'patientModel'=> $patientModel, 'symptomHistoryEvents'=>$symptomItems
        ));
    }
    else //else throw exception
    {
        throw new CHttpException(403, 'You are not permitted to check this patient\'s Symptom History');
    }
}

(sorry for the extra long code, but I honestly have no idea what might help and what might not).

I repeat I get a 404 error, not a 403 one.

Does anyone have any idea why I am getting this error? Thank you for your help :)

解决方案

This is similar to this question here: Yii 1.14 controller from two parts in module produce 404 error

Differences between environments can lead to 404s of this nature, due to naming conventions with controllers. Since upper case and lower case characters have different ASCII values, certain environments will evaluate them differently.

In my experience, naming controllers following this pattern: FooController.php, where the first letter and the "C" in Controller are capitalized and nothing else, seems to work in all environments.

这篇关于当我调用特定操作时,上传到主机上的 Yii 应用程序会出现 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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