1

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:

  1. Do I need to create a new MVC design for the mobile pages, or can I use the Model of the regular website?

  2. 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 'mobiles\main.php';  
    } else {  
        include 'web\main.php';  
    }
    

    With the "m" sub-domain, you must have different Controller. Not so?

1 Answer 1

1

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
  • Can you please add an answer to my second question? If website use other domain name for mobile, how they using the same controller? Commented Mar 3, 2014 at 18:09
  • Domain name is a web-server level construct, You could have both domain names pointing to the same application, and then within your application code, do Request.Url.Hostname (or whatever it is in php to get the hostname) to differentiate between the two.
    – Matthew
    Commented Mar 3, 2014 at 18:40
  • I see, I didn't know that. I am hosting temporally in some hosting site, and it limits the sub-domains to be in separated directories. Thank you! Commented Mar 3, 2014 at 18:51
  • Personally I'd lean towards responsive design instead of two different sites. Less code to maintain and easier to manage. Yes, there is a learning curve but thanks to frameworks like Bootstrap and Foundation those curves are less steep then before.
    – MBonig
    Commented Mar 3, 2014 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.