Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a mobile version for my web app in CodeIgniter

I'm using CodeIgniter to develop a new web app, and I'd like to create a mobile version that users get redirect to when they visit it from their phones.

The mobile version of the app should have a different flow, so swapping CSS/HTML files in the code is not an option for me since the mobile version and the web version will handle things differently in their Controllers and Views, while sharing the same Models.

Anyway how I could do this efficiently?

Your help is much appreciated. :)

like image 788
KeyStroke Avatar asked May 27 '10 12:05

KeyStroke


2 Answers

If you really need 2 independant apps, you can setup this with juste one or two codeigniter core modification, depending if you're using PHP4 or 5.

We've done it following this CI's wiki page and it works great, we share models, libraries, configuration. Basically you got a project organization like this :

/application/
   /common/<similar to application directory, but used for shared libs/helper/models/configs files>
   /frontend/<similar to application directory>
   /backend/<similar to application directory>
/system/

By overriding loaders you can implement loading priority if the same lib/config is present for common classes or app-specific). Also you can move all common code (controllers, specific routing class, etc.) and keep only application specific overloadings in your apps.

In the end you got two Front Controllers (mostly identical to the index.php file) one for each app, and you're free to filter visitors with url rewriting, specific subdomain, etc.

If you're targeting servers running PHP4, I opened this thread on codeigniter forums to see what to change in core classes to get it to work (without modification there is a loading issue)

Another viable alternative, but I haven't used it yet, is using HMVC organisation

like image 74
Benoit Avatar answered Oct 13 '22 01:10

Benoit


Solution (a):

  • Check in a global controller if the user uses a mobile or a desktop client
  • Load controllers based on the client version (controller_default.php / controller_mobile.php)
  • Do all the client-specific stuff twice
  • Views can be stored in different folders

Note: (a) becomes messy if your application grows over the time.

Solution (b):

  • Modify index.php to load different application folders based on the client used
  • Store your models/configs/libs in a shared folder

Any of the above required (extensive?) modification of the CI framework. Try to do as much as possible by overwriting the existing classes (MY_Controller etc.) to be able to update at a later time.

like image 34
Philipp Avatar answered Oct 13 '22 01:10

Philipp