Creating a mobile version for my web app in CodeIgniter

KeyStroke picture KeyStroke · May 27, 2010 · Viewed 7k times · Source

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. :)

Answer

Benoit picture Benoit · May 27, 2010

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