user agent - Codeigniter user_agent -


this first time developing responsive website, , attempted using codeigniter user_agent class.

i notice there's

is_mobile() 

and

is_browser() 

however, picture have in mind website on tablet pretty similar browser, , mobile site load different view file altogether.

however, is_mobile() includes both tablets , mobile phones, , it's not i'm hoping for. there alternative this?

reason: using jquery mobile, , load different layout mobile phone, , don't want view appear on tablets.

you have couple of options.

you can extend library , create method check tablet:

class my_user_agent extends ci_user_agent {      public function __construct()     {         parent::__construct();     }      public function is_tablet()     {         //logic check tablet     } }  // usage $this->load->library('user_agent'); $this->user_agent->is_tablet(); 

or override existing is_mobile() method in library have functionality want:

class my_user_agent extends ci_user_agent {      public function __construct()     {         parent::__construct();     }      public function is_mobile()     {         // can copy original method here , modify needs     } }  // usage $this->load->library('user_agent'); $this->user_agent->is_mobile(); 

http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html


example

application/libraries/my_user_agent.php:

class my_user_agent extends ci_user_agent {      public function __construct()     {         parent::__construct();     }      public function is_ipad()     {         return (bool) strpos($_server['http_user_agent'],'ipad');             // can add other checks other tablets     } } 

controller:

public function index() {     $this->load->library('user_agent');      ($this->agent->is_ipad() === true) ? $is_ipad = "yes" : $is_ipad = "no";      echo "using ipad: $is_ipad";  } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -