【发布时间】:2018-03-31 03:51:46
【问题描述】:
您好,我正在开发一个事件管理站点,我在控制器上使用 if else 语句来导航 2 个视图页面(一个带有文件附件的视图页面和一个没有文件附件的视图页面)我的问题是每次执行 if来自我的控制器的 else 语句我总是以数据库上没有附加文件的情况结束(空)
这是我的控制器:
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 列是否为空,但我总是最终加载没有附加文件或 (event_file == null) 的视图文件,即使有。
谢谢。
【问题讨论】:
-
试试
is_null($check->event_file)或$check->event_file === null -
@ArtisticPhoenix ok 试试看谢谢
-
@ArtisticPhoenix 问题依旧
-
你能检查一下 $check 变量给出了什么吗?
-
我以为会的,只是
null == false == 0 == '' == []等等...
标签: php codeigniter if-statement null