I have developed a full website with CakePHP framework and we'd like to make a very light version of the website for mobile devices (mainly iPhone/iPad).
Is there a way to use the existing website with a new sub domain (for instance mobile.mywebsite.com) which will render specific views? I would like to avoid copying and simplifying the current one to match the new one requirements. I do not want to have to "re-develop" a new CakePHP website and do the changes twice every time I need to change a controller action.
The simple solution is to create a new 'mobile' layout with respective stylesheet(s) and turn it on in AppController:
It is important to do that in
beforeRender()
in case if you change$this->layout
in your controllers' methods.I modified this technique for a CakePHP 2.1 app. Here is my
beforeFilter()
:And here is my
afterFilter()
:This helps account for deprecated verbiage and constants in CakePHP 2.