Posts Tagged ‘Symfony’

jfCachePlugin: two Filters that might help to make your pages cacheable (client-side)

Sunday, March 6th, 2011

Today I packaged two filters I am using to manage client side caching:

  • jfCacheHeadersFilter: sets the HTTP headers required to server pages from client side (or proxy) cache
  • jfCacheInvalidateStaticSourceUrlsFilter: append a cache key to the URLs of referenced Javascript and CSS files so that you can configure a very long cache expire time for those files

(more…)

jfPortableDevicePlugin: Symfony to go

Sunday, February 27th, 2011

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/.

(more…)

Allow empty selection in sfWidgetFormDoctrineChoice / Unline doctrine relations

Tuesday, October 12th, 2010

The standard sfWidgetFormDoctrineChoice “add_empty” option is only useful if the relation has not yet been set. However, once a relation is saved, selecting the empty value again will result in an validation error.

Here is a simple way to allow users to unlink relations by selecting the empty value of a sfWidgetFormDoctrineChoice select list. Simply add these lines to your form’s configure()-method:

$this->widgetSchema['rdr_images_list']->setOption('add_empty', true);
$valuesRaw = sfContext::getInstance()->getRequest()->getParameter($this->getName());
if (1 === count($valuesRaw['images_list']) && '' === $valuesRaw['images_list'][0]) {
  $this->validatorSchema['images_list'] = new sfValidatorPass();
}

Symfony Filter: redirect depending on requesting user agent (e.g. detect mobile devices)

Thursday, November 26th, 2009

I wrote two filters that allow you to configure redirect rules for requests sent from special user agents e.g. iphone, android & co.

If the requesting user agent matches the redirect rules then the redirect is issued using HTTP Headers. As a fallback for cached pages, the redirect is issued again using javascript (the filter inserts some lines of javascript code in the -section of your document).

The first one, redirectUserAgentFilter, is a generic approach to redirects depending on the user agent string. You can activate it in your filters.yml using these lines:

redirectUserAgent:
  class:  redirectUserAgentFilter
  enabled: on
  param:
    redirectUrl: http://mobile.yourdomain.com
    userAgents:
      - android
      - iphone
      - ipod

In this case, the filter would redirect all requests coming from user agents containing “android”, “iphone” oder “ipod” in their names to http://mobile.yourdomain.com.
(more…)

Symfony link tags (e.g. canonical)

Friday, October 23rd, 2009

Unfortunately, symfony does not (yet, see http://trac.symfony-project.org/ticket/7282#comment:3) provide an easy and intuitive way to add ‘<link rel=”XXX” href=yyy” />’ tags which you might need e.g. to avoid duplicate content using canonical tags. Therefore I added a simple helper method ‘add_link’ which takes an href and a rel parameter and then creates and stores the according link tag in a slot named ‘links’:

(more…)

Symfony Forms and “old” dates

Monday, October 12th, 2009

I just contributed a patch to the Symfony Project that caused errors when populating forms with dates prior to Fri, 13 Dec 1901 i.e. exactly 81 years earlier than my date o brith (which was not a friday, luckily).

I noticed the problem when working on Brigitte.de’s baby name finder: Under http://www.brigitte.de/brigitte.php/liebe-sex/vornamen-finden/isabel.html you see the birth date of “Isabella von Frankreich”, the daugthe of King Philipp IV is 1970 -01-01 but actually it should be 1292-03-17.

(more…)