您好我正在开发一个事件管理网站,我在我的控制器上使用if else语句导航2个视图页面(带有文件附件的视图页面和没有文件附件的视图页面)我的问题是每次执行if时来自我的控制器的else语句总是最终导致数据库上没有附加文件的情况(null)
这是我的控制器:
public function viewevent(){
$id = $this->uri->segment(3);
$data['events'] = $this->EventModel->getEventII($id);
$check = $this-$this->EventModel->getEventII($id);
if($check->event_file == null){
$this->load->view('include/schoolrep/toppage', $data);
$this->load->view('include/schoolrep/header', $data);
$this->load->view('schoolrep/viewevent2', $data); // loads page where there is no file attached
$this->load->view('include/schoolrep/footer', $data);
}else{
$this->load->view('include/schoolrep/toppage', $data);
$this->load->view('include/schoolrep/header', $data);
$this->load->view('schoolrep/viewevent', $data); //loads page where there is file attached
$this->load->view('include/schoolrep/footer', $data);
}
}
这是我的模特
public function getEventII($id){
$q = $this->db->get_where('tblevents',array('event_id'=>$id));
return $q->row();
}
正如你在我的if else语句中看到的那样,我在数据库中检查我的event_file列是否为null但是我总是最终加载没有附加文件的视图文件或者(event_file == null)尽管有。。
感谢。
答案 0 :(得分:2)
您可以将this
行更改为
$check = $this-$this->EventModel->getEventII($id);
此
$check = $this->EventModel->getEventII($id);