Cakephp控制器操作不会在live server上重定向

Cakephp控制器操作不会在live server上重定向,cakephp,redirect,Cakephp,Redirect,我有一个在4个模型中保存数据的操作。这是我的控制器代码。我确实在保存数据时遇到任何错误,我仔细检查了它,但这个操作在保存数据后不会重定向到给定的url,它显示的只是同一个操作(用于保存数据的操作)的空白页。此问题仅在live server上存在。在我的本地版本中,它运行良好 if ($this->request->is('post')) { //First upload user pic if ($this->request-&g

我有一个在4个模型中保存数据的操作。这是我的控制器代码。我确实在保存数据时遇到任何错误,我仔细检查了它,但这个操作在保存数据后不会重定向到给定的url,它显示的只是同一个操作(用于保存数据的操作)的空白页。此问题仅在live server上存在。在我的本地版本中,它运行良好

if ($this->request->is('post')) {
            //First upload user pic
            if ($this->request->data['FacilityResident']['pic']['name'] != NULL) {
                $pic = $this->request->data['FacilityResident']['pic']['tmp_name'];
                if (!is_dir(WWW_ROOT . 'img' . DS . 'residents' . DS)) {
                    mkdir(WWW_ROOT . 'img' . DS . 'residents' . DS);
                    chmod(WWW_ROOT . 'img' . DS . 'residents' . DS, 0777);
                }
                $uniq = mt_rand();
                move_uploaded_file($pic, WWW_ROOT . 'img' . DS . 'residents' . DS . $this->request->data['FacilityResident']['pic']['name']);
                $this->request->data['FacilityResident']['avatar'] = DS . 'residents' . DS . $this->request->data['FacilityResident']['pic']['name'];
                unset($this->request->data['FacilityResident']['pic']);
            }

            $this->request->data['FacilityResident']['facilities_id'] = $this->Session->read('urlparam.facilityId');
            $this->FacilityResident->save($this->request->data['FacilityResident']);
            $residentId = $this->FacilityResident->getLastInsertID();
            if (!empty($this->request->data['FacilityResidentDietary']['diet'])) {
                $dietData = implode(',', $this->request->data['FacilityResidentDietary']['diet']);
                unset($this->request->data['FacilityResidentDietary']['diet']);
                $this->request->data['FacilityResidentDietary']['diet'] = $dietData;
            }
            $this->request->data['FacilityResidentDietary']['facility_residents_id'] = $residentId;
            $this->FacilityResidentDietary->save($this->request->data['FacilityResidentDietary']);
            $this->request->data['ResidentMealschedule']['facility_residents_id'] = $residentId;
            $this->ResidentMealschedule->save($this->request->data['ResidentMealschedule']);
            $residentMealSchedultId = $this->ResidentMealschedule->getLastInsertID();
            foreach ($this->request->data['Mealdetail'] as $key => $value) {
                if ($key == 'Bread') {
                    $value[0]['attribute_four'] = implode(',', array_filter($value[0]['attribute_four']));
                }
                foreach ($value as $val) {
                    $this->Mealdetail->saveAll($val);
                    $data['Mealschedule']['meal_types_id'] = 1;
                    $data['Mealschedule']['resident_mealschedule_id'] = $residentMealSchedultId;
                    $data['Mealschedule']['mealdetails_id'] = $this->Mealdetail->getLastInsertID();
                    $this->Mealschedule->saveAll($data);
                }
                unset($data);
                unset($val);
            }
            $i = 1;
            foreach ($this->request->data['ResidentMealMeta'] as $key => $val) {
                $data['ResidentMealMeta'][$i]['resident_mealschedule_id'] = $residentMealSchedultId;
                $data['ResidentMealMeta'][$i]['meal_value'] = $key;
                $data['ResidentMealMeta'][$i]['meal_option'] = $val;
                $i++;
            }
            if (!empty($this->request->data['ResidentTray']['tray'][0])) {
                $j = count($data['ResidentMealMeta']) + 1;
                $data['ResidentMealMeta'][$j]['meal_value'] = 'tray';
                $data['ResidentMealMeta'][$j]['resident_mealschedule_id'] = $residentMealSchedultId;
                $data['ResidentMealMeta'][$j]['meal_option'] = implode(',', $this->request->data['ResidentTray']['tray']);
            }
            unset($this->request->data['ResidentMealMeta']);
            unset($this->request->data['ResidentTray']);
            if ($this->ResidentMealMeta->saveAll($data['ResidentMealMeta'])) {
                $this->Session->setFlash('New resident added', 'flash', array('alert' => 'success'));
                if(isset($url)){
                    unset($url);
                }
                $url = Router::url(array(
                            'controller' => 'residents',
                            'action' => 'resident_list',
                            '?' => array('facility_name' => $this->Session->read('urlparam.facilityName'), 'facility_id' => $this->Session->read('urlparam.facilityId'))
                ));
                $this->redirect($url);
            }
        }

这里有人能告诉我出了什么问题吗?我也尝试过通过相关模型保存数据,但没有效果。

我建议使用此解决方案:

Router::redirect(
    '/controller_where_you_re_saving_data/*',
    array('controller' => 'residents', 'action' => 'resident_list'),
    // view action expects $id as an argument
    array('facility_name' => $this->Session->read('url.facilityName'))
);
但是,我建议在涉及会话值时不要传递参数,因为您可以在项目中的每个控制器中访问它,这使得解决方案如下所示:

Router::redirect(
    '/controller_where_you_re_saving_data/*',
    array('controller' => 'residents', 'action' => 'resident_list'),
  );
文件如下:

希望能有帮助