I am building a small website, in PHP and I am using MVC design pattern for the UI.
In the future I will need to add mobile support for my website. It will be in the sub domain “m” like everyone.
All the web is new for me, and I am new with MVC too. I did for each page View, Model and Controller. The Views and the Models are in some internal directory, and the controller is in the public directory of the server (the servers root directory).
My Questions:
-
Do I need to create a new MVC design for the mobile pages, or can I use the Model of the regular website?
-
Most of sites have “m” sub-domain for mobile web pages. But the only thing that need to change is the View part. If the public page is the Controller, why not to create only Views for the mobile pages, and the Controller will decide which View will present? Like:
if ($isMobile) { include 'mobilesmain.php'; } else { include 'webmain.php'; }
With the “m” sub-domain, you must have different Controller. Not so?
My recommendation for this, if you consider both desktop and mobile browsers to be first class citizens, then I would just have separate views for mobile and desktop, while the models and controllers are shared between the two.
Alternatively, you could use one set of views and use responsive design to account for the different devices, but personally I find this to be much more difficult and imposes more constraints on each device.
4