0

I have a question about developing for mobile and desktop.
i need offer a mobile and other content for desktop... The idea is the following:
[mobile] text content only with a few menu items
[desktop] content complete with text and pictures, with all menu items

to solve this problem, I have the idea that the controller identifies the request, then it will load the model_mobile / model_desktop and view_mobile / view_desktop... is that correct?

basically would be in the controller:

if ($ request-> ismobile () === true)
{
include 'model_mobile.php';
include 'view_mobile.php';
}
else
{
include 'model_desktop.php';
include 'view_desktop.php';
}
Papa Charlie
  • 625
  • 8
  • 31
  • I guess, the model should be the same, just change the views and the information you pass to them. Ofcourse, you will need a different set of controllers, that interact with the user. – Mārtiņš Briedis Jul 14 '12 at 07:40

2 Answers2

2

Presentation logic is the purview of View instances ( fyi, views are not dumb templates ).

Just because you decided to interact with the site via mobile device instead of desktop does not change the domain business logic. Model stays the same. This change affects only view and depends on how well written your views are. Basically there are two options:

  1. View uses different templates for desktop and mobile; requests required information from model layer; renders templates. This relies on fact, that most of the information will be the same for both mobile and desktop clients.

  2. You have different view for mobile and desktop, and it is already known which templates are available for each view. In this case view requests on very specific information from model layer, before rendering it with templates.

The second way would be better for high-load systems (you might save a little by having more precise interaction with storage), but come with some code duplication.

Of course you could have such precise requests in option nr.1, but that would require to have a if ($desktop) .. else block repeating though-out the view, and would be a clear sign, that code has to be split in two classes and polymorphism employed.

What about the controllers ?

In both options controller stays the same. It only affects view by either changing a state of view (in first case) or deciding, which type of view will be created (in second case).

If you need to hide some controller actions from mobile users (which would be already partially accomplished by having different templates), you could implement some sort of ACL, which lets you decide, if user is allowed to access specific method on the controller.

Of course, this all depends on your understanding of MVC.

Community
  • 1
  • 1
tereško
  • 58,060
  • 25
  • 98
  • 150
0

I would do as follows:

  1. In the bootstrap, detect that it is a mobile request
  2. Redirect user to, possibly, a m. subdomain
  3. m. subdoimain is routed to special mobile controllers
  4. Mobile controllers are practically the same normal controllers, which just views for mobilde devices and offers a bit more limited features than normal controllers.

Models should be used the same to avoid code duplication.

Mārtiņš Briedis
  • 17,396
  • 5
  • 54
  • 76
  • understand the use of the same model, but we suppose that for a desktop device I show the comments of a news along with the image of the profile and the mobile device I just show the name of the author of the comment. how to solve this? thank you – Papa Charlie Jul 14 '12 at 07:47
  • You just use a different view. – Mārtiņš Briedis Jul 14 '12 at 07:49
  • but I'll have a model taking information from the database will not be used ... this is not a problem? – Papa Charlie Jul 14 '12 at 07:50
  • Ok, so It depends on how you understand MVC. I understand it as controller talkts to model and to view. View can retrieve information from model, but it doesn't change models state. – Mārtiņš Briedis Jul 14 '12 at 08:20