我是 codeigniter 的新手。我正在尝试制作一个简单的网站,如果该网站已启用 (1) 或未启用 (0),它将在数据库中获取其“设置”。
我正在尝试确定站点设置是否启用 (1) 或未启用 (0) 并显示索引 View (如果站点值 == 1)
和维护 View (如果站点值为 == 0 或 null)
我已经编写了代码,并且可以在 View 中回显“站点”值。
模型
function getsetting() {
$this->db->select("site");
$this->db->from('configuration');
$query = $this->db->get();
$ret = $query->row();
return $ret->site;
}
Controller
//if site value is == 1 load the normal view
$this->load->view('index', $data);
//else load the maintenance view
$this->load->view('maintenance', $data)
我有一个数据库“mysite”,其中包含一个表“configuration”和一列“site”,值 [null 或 1] 来自 site 列,用于确定应显示哪个 View 。
接受任何帮助。提前致谢。
最佳答案
型号
在这里,您需要使用 $query->row();
获取单行并将其传递给 Controller
function getsetting() {
$this->db->select("site");
$this->db->from('configuration');
$query = $this->db->get();
$ret = $query->row();
return $ret->site;
}
As you describe in your question
the values [null or 1]
Controller
function your_controler() {
$this->load->model('model_file');
$site = $this->model_file->getsetting();
if(isset($site) && $site==1){// your condition here
$this->load->view('index', $data);
}else{
$this->load->view('maintenance', $data)
}
}
关于php - 如何根据 Controller 中的条件加载 View (Codeigniter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30680637/