jfPortableDevicePlugin: Symfony to go

I wrote a symfony plugin that allows you to easily optimize your existing symfony application for mobile devices using jQuery Mobile.
And if you want to distribute your application in Android Market or Apple App Store it is possible using e.g. Phonegap.

If you wish to see the plugin in action you can visit the mobile version of my web page http://www.jonasfischer.net/m.

If you are visiting my website using one of the supported operating systems (e.g. iOs or Android) then you will be prompted if you wish to view the mobile-enhanced version or the regular version: http://www.jonasfischer.net/.

Features

  • jQuery Mobile integration
  • jfPortableDevicePlugin is bundled with a standard template and theme to get your app up and running within minutes
  • automatically “hijacks” links and appends some parameters to the URLs so that you can apply special logic in your symfony actions/templates if needed
  • flexible and extendable using symfony standards: The templates are organized in a very fine-grained manner so that you can override the parts that don’t fit your needs.
  • Comes with a phonegap build-mode option to prepare your app for deployment using phonegap.

Installation instructions

Checkout the Source Code:

$ svn co http://jfportabledevice.googlecode.com/svn/trunk plugins/jfPortableDevicePlugin

Be aware that you are checking out the trunk. As this plugin is still under heavy development (in fact, the jQuery Mobile library itself is still in alpha state) there is no stable tag/branch, yet.

Enable plugin jfPortableDevicePlugin in your ProjectConfiguration.php

As Victor points out in the comments, if you have not enabled all plugins by default, you need to enabled jfPortableDevicePlugin manually:

$this->enablePlugins(’jfPortableDevicePlugin’);

Enable module jfPortableDevice in your settings.yml

enabled_modules: [..., jfPortableDevice]

Publish plugin assets

$ php symfony plugin:publish-assets

Enabled filters in your filters.yml

required: jfPortableDeviceFilter

This filter automatically sets the correct layout for portable device requests.

jfPortableDevice:
class:  jfPortableDeviceFilter
param:
layout: jfPortableDeviceLayout

Additionally, you need to ensure that the specified layout file exists in your app’s layout folder.
To get up and running you can use the bundled jfPortableDeviceLayout.php file. Simply symlink or copy it into your app’s layout folder:

$ ln -s ../../../plugins/jfPortableDevicePlugin/templates/jfPortableDeviceLayout.php apps/frontend/templates/jfPortableDeviceLayout.php

or

$ cp plugins/jfPortableDevicePlugin/templates/jfPortableDeviceLayout.php apps/frontend/templates/

optional: redirectByUserAgentPortableDevice

This filter redirects to the portable device controller if a request was made from one of the specified user agents

redirectByUserAgentPortableDevice:
  class:  redirectByUserAgentPortableDeviceFilter
  param:
    redirectUrl: /m/#%s?jfPD_device=portable
    noHeaderRedirect: true
    javascriptConfirm: true
    stopParameters:
      - noMobileRedirect
    stopModules:
      - jfPortableDevice
    userAgents:
      - iphone #really bad example string because it might easily be miss-matched. Choose whichever regular expressions fit your needs
      - ipod #really bad example string because it might easily be miss-matched. Choose whichever regular expressions fit your needs
      - ipad #really bad example string because it might easily be miss-matched. Choose whichever regular expressions fit your needs
      - android #really bad example string because it might easily be miss-matched. Choose whichever regular expressions fit your needs

Clear the symfony cache

$ php symfony cc

Tags: , ,

5 Responses to “jfPortableDevicePlugin: Symfony to go”

  1. Victor Ruiz says:

    Hi, I’m very interested on this plugin!

  2. Victor Ruiz says:

    One step is required before the publish-assets task execution:

    - Edit [project]/config/ProjectConfiguration.php file and enable ‘jfPortableDevicePlugin’ by writing the next code:

    $this->enablePlugins(’jfPortableDevicePlugin’);

    If you don’t do this, assets won’t be published.

  3. Victor Ruiz says:

    In my case, I’m using this plugin in a standalone application, and not integrated in an existent one, so I had to add the next helpers to settings.yml:

    # Helpers enabled globally
    standard_helpers: [Partial, Cache, I18N]

    I also needed to set up the homepage in routing.yml as shown below:

    homepage:
    url: /
    param: { module: jfPortableDevice, action: index }

  4. Steve Y says:

    Jonas,

    Great looking plugin! I was wondering how far back compatibility goes for Symfony. How adaptable is this to Symfony 1.0? I’m looking to get a Symfony site on jQuery Mobile with not a lot of tweaking hopefully using this plugin.

  5. Jonas Fischer says:

    Steve,

    I already made some changes to support Symfony 1.0 and I know of at least one project running this Plugin on Symfony 1.0.
    Unfortunately the documentation contained in this blog post is a little bit out of date. I suggest you look directly into the source code to get it running.

    Currently I am still making changes to the svn trunk. If you want to use the plugin in a production environment, please let me know. I will then create a stable tag.

Leave a Reply