I lost my cellphone last night, which sucks because the phone I want isn’t going to be available until July 11th. I’ll get a loaner phone until then, but it is exciting times to be a web developer. Why? Because the introduction of the iPhone there is a renewed interest in web sites that cope well with mobile browsing. I’m working on an app that is perfect for mobile browsing, but that is still down the road.
Anyhow, I saw a post the other day showing how to create an iPhone-optimized version of your Symfony app. Yawn. Cake had that a year ago.. No code provided *but* the article does tell you exactly how he did it.
But that’s really the key here. You don’t need to do anything special to make a web-based app in CakePHP that will work nicely on your iPhone. Contrast that to all the stuff I see in that article that you need to do. Off the top of my head, it seems to me the best way to do it is:
- create CSS and layouts for regular and iPhone versions of your application
- do a check in your beforeFilter() method where you check the User-Agent
- pass that info to your actions, and render whichever layout+CSS you need
Compare the Symfony article to the CakePHP article plus my notes, and let me know what you think.
Tags: CakePHP, iPhone

Man, I hear you, I’m probably getting one on the 11th. They’re so cheap, the fiancee might bite as well.
Yeah.. the iPhone
The 3G is exactly what it should have been in the first place. Good to see that Apple recognize mistakes and responds (just like with apple.tv 2.0).
I would have compared with symfony but that code looks way to complicated. This custom setup config looks alot like Lighttpd (which is awful too). I don’t even wanna try to understand it. It’s too early for me.
What i suggest is to not touch the actions for this. I would use the RequestHandler and created subfolder in the view folders called “iphone” and change the layout to “iphone.ctp” instead of “default” or whatever it is. Seems cleaner to me than if(iphone) render(instead) set(style,iphone) in each and every method. Just like how it’s done with rss, xml, json, etc..
Heh, this reminds me of a post made by maddox:
http://www.thebestpageintheuniverse.net/c.cgi?u=iphone
Please don’t get insulted or anything
Okay, let’s say you want to re-use your logic, but present radically dumbed down templates.
Ones that’ll be viewable on any mobile browser, not just iPhone’s Mobile Safari.
Changing the CSS isn’t enough, because there’s too much info on a too-tiny screen.
Would you do a browser/resolution detect in your before filter, and have your View automagically alter its script path from /views/default/ to /views/mobile/ ?
@derek
If all the actions in your controller need that, then the before filter is the best place to put it.