views:

178

answers:

3

I have a controller build for a web application with a web presentation. But now I need to create a iphone (mobile phone) version of this application.

Basically this is a blog application with comments. In the regular version comments are loaded at the same time as the entry. But on the mobile application I want to comments to be load on request. How do you achieve that.

  • 1 controller 2 views : 2 different action (one for each view). But I can have a lot of actino that will be similar but not exactly. And routing will be an issue
  • 2 controller 1 view per controller : 1 manage the regular version the other manage the mobile version.

I open to other ideas. BTW I use Zend Framework.

A: 

I think the "RESTful" way to do it would be to use the same URI (so same controller/action), and to detect (either from session, or by looking at the User Agent header) whether you want to render the full version or the mobile version.

So you'd only have one controller/action which looked like this:

class BlogController {
    function ShowPost() {
        if (IsMobile) { 
            View("PostWithComments_Mobile");
        } else {
            View("PostWithComments");
        }
    }
}

Depending on how much control you have over the framework (I don't know PHP nor Zend) you might be able to automatically have it switch to a different view depending on whether a mobile version exists and the user agent.

A quick Google search results in many samples for detecting mobile browsers.

Paul Stovell
I thought about that but it was more a general question related to MVC. how do you create different presentation for the same controller. What if I have to create 10 different presentation. Is there a good pattern to do it?
stunti
A: 

I would suggest outputting views in XML then using respective XSL file to transform them into full or stripped-down HTML depending on the targeted screen size. I am sure you can post-process view returned from controller in ZF. Just checked XML+XSL transformation on my friend's iPhone and it works perfectly.

Michał Rudnicki
A: 

You should define a ContextSwitch action helper. You'd also need a way to recognize requests made from iPhone platforms.

Ionuț G. Stan