title: How to load a View based on multiple conditions in Controller (Codeigniter)
body: <p>I'm new to codeigniter. I'm trying to make a simple site, with three (3) conditional views. <br></p>
  
  <p>For example:<br>
  If "user_agent" detects mobile device -> load mobile_view <br>
  else load -> web_view <br>
  and if "site" settings is disabled [value = 0] load -> maintenance_view</p>
  
  <p><br>
  I have the following code but doesn't work. It always load the maintenance view.</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>function index() {
          $this-&gt;load-&gt;library('user_agent');
          if($this-&gt;agent-&gt;is_mobile())
          {
              $this-&gt;load_mobile();   
          } else {
              $this-&gt;load_web();
          }
      }
  
      public function load_web() {
         $site = $this-&gt;Datamodel-&gt;getsetting();
         if(isset($site) &amp;&amp; $site==1) { //check if site settings is enabled [(if site "value == 1" load -&gt; web_view) ELSE (site "value == null" load -&gt; maintenace_view)]
              $this-&gt;load-&gt;view('web_view');
          } else {
              $this-&gt;load-&gt;view('maintenance_view');
          }
      }
  
      public function load_mobile() {
          $this-&gt;load-&gt;view('mobile_view');
      } 
  </code></pre>
  
  <p><br>
  <strong>Model</strong> for site settings:</p>
  
  <pre><code> function getsetting() {
      $this-&gt;db-&gt;select("site");
      $this-&gt;db-&gt;from('configuration');
      $query = $this-&gt;db-&gt;get();
      $ret = $query-&gt;row();
      return $ret-&gt;site;
    }
  </code></pre>
  
  <p><em>For site settings conditions, I have extendted my old code from here</em> <a href="https://stackoverflow.com/questions/30680637/how-to-load-a-view-based-on-condition-in-controller-codeigniter">How to load a view based on condition in Controller (Codeigniter)</a></p>
  
  <p><em>The previous code only have 2 conditions if site is enabled</em> [site value == 1] <em>or not</em> [site value == null] </p>
  
  <p>Depending on conditions, web or index view is loaded in controller if site "value == 1" otherwise if site "value == null" load the maintenace view</p>
  
  <p><br><em>Now Im trying to add a mobile view, but I cant figure it out how, with the rest of the code.</em></p>