Navigation

Stumbling over a post in the symfony-users list I wrote down some information on how we manage mobile sites in our ullright platform:

There’s an old blog post about creating an symfony iPhone view:
http://www.symfony-project.org/blog/2008/06/09/how-to-create-an-optimized-version-of-your-website-for-the-iphone-in-symfony-1-1
Most of it is still valid and it works.

But there is one serious drawback: You have to provide a mobile template for each action.
That’s why we created a tiny patch to provide a fallback to normal templates in case there is no special mobile one.

Here are the required parts:

Mobile detection: This belongs into your project configuration:
http://trac.ullright.org/browser/trunk/plugins/ullCorePlugin/config/ullCorePluginConfiguration.class.php

Symfony patch enabling fallback to html templates: (Patches sfView.class.php)
http://trac.ullright.org/browser/trunk/plugins/ullCorePlugin/patch/sfView.patch.txt

Finally provide a mobile template (or not):
Normaly you would put your template in apps/frontend/modules/myModule/templates/myActionSuccess.php
Now you can provide a mobile template by creating the following file: apps/frontend/modules/myModule/templates/myActionSuccess.mobile.php

This also works for layouts, partials and components. Example: apps/frontend/modules/myModule/templates/_head.mobile.php

Here’s the original post: http://groups.google.com/group/symfony-users/browse_thread/thread/9da0a9fe3cf3ff77

Have a nice day!

Posted Tuesday, September 7th, 2010 at 09:02
Written by: | Filed Under Category: Best Practices
You can leave a response, or trackback from your own site.

5

Responses to “Creating mobile symfony sites”

[...] [WebDev::Symfony] Créer des sites pour mobile avec symfony, voir ça aussi [...]

[...] Creating mobile symfony sites. Tworzenie stron dla urządzeń mobilnych w symfony. [...]

Sören Martius

Well I think that it is always a good solution to handle Mobile detection and all the other stuff within the Frontend. The apps logic should be the same… why not using frameworks like bootstrap+responsive? There is an good implementation in the MopaBootStrapBundle which you can find here:
https://github.com/phiamo/MopaBootstrapBundle

Hi Sören,
(I hope this is your first name ;-)

Thank you for your input, and in times of responsive design you’re probably right. This article is a bit old and it’s for symfony 1!

Have a nice day,
Klemens

I checked this solution for sfView.class.php and works OK, but i also needed to add a call to “$this->enableFallbackForMobileRequestFormat();” on the configure method of the sfPartialView.class.php, in order to work for partials drawing also.

Leave a Reply

 

Additional Resources