diff --git a/core/MY_Controller.php b/core/MY_Controller.php index 63bd2d3..f803bf5 100644 --- a/core/MY_Controller.php +++ b/core/MY_Controller.php @@ -105,11 +105,20 @@ public function _remap($method) */ protected function _load_view() { + // Using the 'user_agent' library to identifiy the user's browser + // If it' a mobile one, load a view with '_mobile' (like login_mobile.php) + $this->load->library('user_agent'); + // If $this->view == FALSE, we don't want to load anything if ($this->view !== FALSE) { + // If the browser is a mobile, let' add a '_mobile' sufix in the view name + $mobile_sufix = NULL; + if ($this->agent->is_mobile() === TRUE) + $mobile_sufix = '_mobile'; + // If $this->view isn't empty, load it. If it isn't, try and guess based on the controller and action name - $view = (!empty($this->view)) ? $this->view : $this->router->directory . $this->router->class . '/' . $this->router->method; + $view = (!empty($this->view)) ? $this->view : $this->router->directory . $this->router->class . '/' . $this->router->method . $mobile_sufix; // Load the view into $yield $data['yield'] = $this->load->view($view, $this->data, TRUE); @@ -132,11 +141,11 @@ protected function _load_view() { if (file_exists(APPPATH . 'views/layouts/' . $this->router->class . '.php')) { - $layout = 'layouts/' . $this->router->class; + $layout = 'layouts/' . $this->router->class . $mobile_sufix; } else { - $layout = 'layouts/application'; + $layout = 'layouts/application' . $mobile_sufix; } }