How to load a view based on condition in Controller (Codeigniter)

后端 未结 3 1098
天涯浪人
天涯浪人 2021-01-21 09:11

I\'m new to codeigniter. I\'m trying to make a simple site, that will get its \"settings\" on the database, if the site is enabled (1) or not (0).

I\'m trying to determi

3条回答
  •  情歌与酒
    2021-01-21 09:43

    MODEL Here you need to fetch single row by using $query->row(); and pass it to 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)
    
            }
    
        }
    

提交回复
热议问题