CodeIgniter中的更新查询后页面未重定向

时间:2018-12-26 06:59:45

标签: php codeigniter-3

我提交表单时,它以Preferences方法进入setPreferences控制器。

下面是我的控制器。

public function index(){
    $data['page_title'] = 'Preferences';
    $this->load->view('admin/common/header',$data);
    $this->load->view('admin/common/sidebar');
    $this->load->view('admin/preferences');
    $this->load->view('admin/common/footer');

}

public function setPreferences(){
    $preferences = $_REQUEST;
    if($this->Preferences_model->set_value($preferences)){ //model is autoloading
        $this->load->view('admin/preferences');
    }
}

在我的模型中,它会过时地更新表,但不会再次重定向到“首选项”页面。现在它将像这样进入空白页 http://localhost:88/personalsite/Preferences/setPreferences

这是我的模特

function set_value($array){
    foreach ($array as $key=>$value){
        $this->db->set('value',$value);
        $this->db->where('name',$key);
        $this->db->update($this->table_name);
    }
    return $this->db->affected_rows();
}

如何将其重定向到视图http://localhost:88/personalsite/Preferences/

我使用了redirect('Preferences'),但它仍然没有重定向。

1 个答案:

答案 0 :(得分:0)

尝试

redirect('preferences');//The function will build the URL based on your config file values(`.htaccess` and `routes.php`).

如果不起作用,请在setPreferences函数中使用else条件,例如:

 if($this->Preferences_model->set_value($preferences)){ //model is autoloading
        $this->load->view('admin/preferences');
    }else{
        echo 'not redirect'; 
        exit; 
    }

还要检查.htaccessroutes.php文件(可能是您的路径将被覆盖)