0

I'm new to codeigniter. I'm trying to make a simple site, with three (3) conditional views.

For example:
If "user_agent" detects mobile device -> load mobile_view
else load -> web_view
and if "site" settings is disabled [value = 0] load -> maintenance_view


I have the following code but doesn't work. It always load the maintenance view.

Controller:

function index() {
        $this->load->library('user_agent');
        if($this->agent->is_mobile())
        {
            $this->load_mobile();   
        } else {
            $this->load_web();
        }
    }

    public function load_web() {
       $site = $this->Datamodel->getsetting();
       if(isset($site) && $site==1) { //check if site settings is enabled [(if site "value == 1" load -> web_view) ELSE (site "value == null" load -> maintenace_view)]
            $this->load->view('web_view');
        } else {
            $this->load->view('maintenance_view');
        }
    }

    public function load_mobile() {
        $this->load->view('mobile_view');
    } 


Model for site settings:

 function getsetting() {
    $this->db->select("site");
    $this->db->from('configuration');
    $query = $this->db->get();
    $ret = $query->row();
    return $ret->site;
  }

For site settings conditions, I have extendted my old code from here How to load a view based on condition in Controller (Codeigniter)

The previous code only have 2 conditions if site is enabled [site value == 1] or not [site value == null]

Depending on conditions, web or index view is loaded in controller if site "value == 1" otherwise if site "value == null" load the maintenace view


Now Im trying to add a mobile view, but I cant figure it out how, with the rest of the code.

4
  • use a switch case statement Commented Jun 9, 2015 at 5:20
  • I'm new to codeigniter, I dont know how. please give example @soul Commented Jun 9, 2015 at 5:22
  • if "site" settings is disabled [value = 0] load -> maintenance_view if(site == 0){ $this -> load->view(maintenance_view);} Commented Jun 9, 2015 at 5:27
  • have you tried using switch case? Commented Jun 9, 2015 at 5:35

1 Answer 1

2
function index() {
if(site_value == 0){
 $this->load->view('maintenance_view');
      }else{
            $this->load->library('user_agent');
            if($this->agent->is_mobile())
            {
                $this->load_mobile();   
            } else {
                $this->load_web();
            }
          }
         }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.