dir:
application -controllers -models -views -mobile_views
How do I auto load templates at mobile_views
when I use $this->load->view
and view by iphone or other mobile phone?
dir:
application -controllers -models -views -mobile_views
How do I auto load templates at mobile_views
when I use $this->load->view
and view by iphone or other mobile phone?
Check this
You can do it in two way.
Way 1: Its very simple. In the above answer (the link I have given) add following line in the end of MyController
function
$this->load->_ci_view_path . = $this->view_type .'/';
You are done. You can simply load view like normal view load.
Way 2: To autoload a view based on user agent, I think you can implement it using hooks. To implement this hooks you need to follow the following steps
Autoload user agent library in autoload.php
$autoload['libraries'] = array('user_agent');
Enable hooks in config.php
$config['enable_hooks'] = TRUE;
Not implement hooks on post_controller_constructor
. Add following codes to hooks.php
$hook['post_controller_constructor'][] = array('class' => 'Loadview', 'function' => 'load', 'filename' => 'loadview.php', 'filepath' => 'hooks' );
Now create a page named loadview.php
under hooks directory having following code
class Loadview { public static $MOBILE_PLATFORM = 'mobile'; public static $DEFAULT_PLATFORM = 'default'; public function load(){ $this->CI =& get_instance(); $view_type = $this->CI->agent->is_mobile() ? self::$MOBILE_PLATFORM : self::$DEFAULT_PLATFORM; $this->CI->load->_ci_view_path = $this->CI->load->_ci_view_path . $view_type .'/'; } }