sfFileValidator pre-defined categories

March 14, 2007

I recently took a look at the source of the sfFileValidation class and found out about a nice, undocumented, “feature” – pre-defined categories. Currently there is just one for web-images, but i hope the list will grow soon.

<?php
$categories = array(
  '@web_images' => array(
    'image/jpeg',
    'image/pjpeg',
    'image/png',
    'image/x-png',
    'image/gif',
  ),
);
?>

So, you could either write:

fields:
  image:
    required:
      msg:      Please upload an image file
    file:       True
    sfFileValidator:
      mime_types:
        - 'image/jpeg'
        - 'image/pjpeg'
        - 'image/png'
        - 'image/x-png'
        - 'image/gif'
      mime_types_error: Only PNG, JPEG and GIF files are allowed

or simply go with:

fields:
  image:
    required:
      msg:      Please upload an image file
    file:       True
    sfFileValidator:
      mime_types: @web_images
      mime_types_error: Only PNG, JPEG and GIF files are allowed

Very useful for lazy developers ;)

Advertisements

One Response to “sfFileValidator pre-defined categories”


  1. […] 14th, 2007 After i found out about the pre-defined categories in sfFileValidator i got curious and took a look at the other validator classes. Turns out there is even more […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: