CodeIgniter Forums
Template for mobile and computer - How? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Template for mobile and computer - How? (/showthread.php?tid=192)



Template for mobile and computer - How? - agriz - 11-10-2014

Hi

In my previous work, I used to detect the device and assigned the theme according to that.

Now, In CodeIgniter, How do i do that?
Something should run before the view is loaded.

How do i do that?


RE: Template for mobile and computer - How? - GrigoreMihai - 11-10-2014

(11-10-2014, 05:58 AM)agriz Wrote: Hi

In my previous work, I used to detect the device and assigned the theme according to that.

Now, In CodeIgniter, How do i do that?
Something should run before the view is loaded.

How do i do that?

For 2.x check here


RE: Template for mobile and computer - How? - agriz - 11-10-2014

Thanks.

Can i run load user agent in pre_controller hooks? Is that good idea?


RE: Template for mobile and computer - How? - GrigoreMihai - 11-10-2014

I use it like in this example in My_controller ...


RE: Template for mobile and computer - How? - kilishan - 11-10-2014

I've recently started using the MobileDetect library for detecting whether it's a phone or tablet. Then, in however you do your views, you can then choose the mobile version or not. Though, to be 100% complete, you'll need to provide a way for the user to go to full site if they desire, even if on a mobile unit.


RE: Template for mobile and computer - How? - Rufnex - 11-10-2014

You can use this lib: http://mobiledetect.net/

download this library and put it inside your library or third party folder and you should be able to use it like that:

Code:
public function index() {
    $this -> load -> library('Mobile_Detect');
    $detect = new Mobile_Detect();
    if ($detect->isMobile())
    {
        echo 'mobile';
    }
}



RE: Template for mobile and computer - How? - Chroma - 11-14-2014

Another approach is to use something like Foundation (http://foundation.zurb.com/) by Zurb or Bootstrap (http://getbootstrap.com/) by Twitter for your responsive template and then only rely on CI for the actual application part.

This might reduce your maintenance and provide a more efficient upgrade path.

Smile


RE: Template for mobile and computer - How? - includebeer - 11-14-2014

+1 for Bootstrap!
No need to detect if it's a phone, a tablet or whatever else. It adjust the layout according to the screen resolution and it's all in CSS!


RE: Template for mobile and computer - How? - tapan.thapa - 11-14-2014

My 2 Cents on Bootstrap...(Responsive design)

1. Our page load time is always high because all content gets loaded (For desktop,tablet, phone) once and then got fit into client's browser as per width and height.

If we go with the user agent identification approach and delivering appropriate view, it will reduce page load time because on mobile phone, we have very less bandwidth.


RE: Template for mobile and computer - How? - Hobbes - 11-17-2014

for the most part responsive design can be handled client side via CSS and javascript. But as tapan.thapa mentioned bandwidth can be an issue because most cell providers limit monthly bandwidth with a cap.

So if you have a site that has large sized Kb like images, ect ... utilizing some type of user agent ident would be a good idea.

when you have the user agent variable you can simply toggle the loaded view between IE: home.php (PC) or home_mobile.php (Tablets, Smartphones, ect ...) this way you can tailor the content to devices with lower bandwidth caps.