重定向数据库中没有配置文件数据
问题描述:
Controller
function view_profil(){
$id = $this->session->userdata('idtabelX');
$profil[''] = $this->class_model->function_model($id);
$this->load->view('view_profil', $profil);
}
Model
function function_model($id){
$this->db->select('*');
$this->db->from('tabelA a');
$this->db->join('tabelB b','b.idtabelB=a.ididtabelB');
$this->db->join('tabelC c','c.idtabelC=a.idtabelC');
$this->db->where('idtabelX', $id);
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->row_array();
}
}
If the profile is clicked, it will show the data user profile stored in database, but if the user does not have the data profile in database, I want to redirect the user to a insert page to populate the profile data.
Thank you very much for help me to resolve this problem.
控制器 p>
function view_profil(){
$ id = $ this-> session-> userdata('idtabelX');
$ profil [''] = $ this-> class_model-> function_model($ id);
$ this-> load- > view('view_profil',$ profil);
}
code> pre>
模型 p>
function function_model( $ id){
$ this-> db-> select('*');
$ this-> db-> from('tabelA a');
$ this-> db- > join('tabelB b','b.idtabelB = a.ididtabelB');
$ this-> db-> join('tabelC c','c.idtabelC = a.idtabelC'); \ n
$ this-> db-> where('idtabelX',$ id);
$ query = $ this-> db-> get();
if($ query-&gt ; num_rows()> 0){
返回$ query-> row_array();
}
}
code> pre>
如果点击了配置文件, 它将显示存储在数据库中的数据用户配置文件,但如果用户在数据库中没有数据配置文件,我想将用户重定向到插入页面以填充配置文件数据。 p>
谢谢你 非常想帮我解决这个问题。 p>
div>
答
In your controller -
function view_profil(){
$id = $this->session->userdata('idtabelX');
$profil[''] = $this->class_model->function_model($id);
//add this bit of code
if($profil[''] == NULL)
{
redirect('your_controller/your_add_method');
}
else
{
$this->load->view('view_profil', $profil);
}
}
You need to use the redirect()
function and pass the url of your controller method for insertion as parameters.