From c587fb327abc5386b175cd38fb004b1e2dd53353 Mon Sep 17 00:00:00 2001 From: Croves Date: Sun, 10 Feb 2013 20:07:57 -0200 Subject: [PATCH 1/5] Added functionality to mobile views --- core/MY_Controller.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/MY_Controller.php b/core/MY_Controller.php index 63bd2d3..d82fc78 100644 --- a/core/MY_Controller.php +++ b/core/MY_Controller.php @@ -105,11 +105,18 @@ 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 ($this->agent->is_mobile() === TRUE) + $view_sufix = '_model'; + // 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 . $view_sufix; // Load the view into $yield $data['yield'] = $this->load->view($view, $this->data, TRUE); From 938dd4eb61470b21d66e6830599205acc0903c96 Mon Sep 17 00:00:00 2001 From: Croves Date: Sun, 10 Feb 2013 20:11:46 -0200 Subject: [PATCH 2/5] Spell and grammar fix --- core/MY_Controller.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/MY_Controller.php b/core/MY_Controller.php index d82fc78..3eeadd6 100644 --- a/core/MY_Controller.php +++ b/core/MY_Controller.php @@ -112,11 +112,12 @@ protected function _load_view() // 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 if ($this->agent->is_mobile() === TRUE) - $view_sufix = '_model'; + $view_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_sufix; + $view = (!empty($this->view)) ? $this->view : $this->router->directory . $this->router->class . '/' . $this->router->method . $view_mobile_sufix; // Load the view into $yield $data['yield'] = $this->load->view($view, $this->data, TRUE); From b938388b6a05a82ec2e281581f1c6eef506d3bb4 Mon Sep 17 00:00:00 2001 From: Croves Date: Sun, 10 Feb 2013 20:24:13 -0200 Subject: [PATCH 3/5] Added the same sufix in the application.php file --- core/MY_Controller.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/MY_Controller.php b/core/MY_Controller.php index 3eeadd6..bf2af47 100644 --- a/core/MY_Controller.php +++ b/core/MY_Controller.php @@ -114,10 +114,10 @@ protected function _load_view() { // If the browser is a mobile, let' add a '_mobile' sufix in the view name if ($this->agent->is_mobile() === TRUE) - $view_mobile_sufix = '_mobile'; + $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_mobile_sufix; + $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); @@ -140,11 +140,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; } } From 41db8594ead038507bf4e2f245903ca6d7e99677 Mon Sep 17 00:00:00 2001 From: Croves Date: Sun, 10 Feb 2013 20:29:13 -0200 Subject: [PATCH 4/5] Fixed issues with --- core/MY_Controller.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/MY_Controller.php b/core/MY_Controller.php index bf2af47..46e4f6c 100644 --- a/core/MY_Controller.php +++ b/core/MY_Controller.php @@ -115,6 +115,8 @@ protected function _load_view() // If the browser is a mobile, let' add a '_mobile' sufix in the view name if ($this->agent->is_mobile() === TRUE) $mobile_sufix = '_mobile'; + else + $mobile_sufix = NULL; // 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 . $mobile_sufix; From 06da4b23ac5c1cc3423e6b572d96dd5c63085de6 Mon Sep 17 00:00:00 2001 From: Croves Date: Sun, 10 Feb 2013 20:32:04 -0200 Subject: [PATCH 5/5] Fixed issues with mobile_sufix variable --- core/MY_Controller.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/MY_Controller.php b/core/MY_Controller.php index 46e4f6c..f803bf5 100644 --- a/core/MY_Controller.php +++ b/core/MY_Controller.php @@ -113,10 +113,9 @@ protected function _load_view() 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'; - else - $mobile_sufix = NULL; // 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 . $mobile_sufix;