Symofny 1.4 form: add validator for alternative email or secret question

I had a case recently – the registration form with alternative email and secret question.
In this form user needed to enter alternative email OR/AND secret question for password reminder function – at least one field must be filled. So I used approach of adding form validators dynamically.


Continue reading “Symofny 1.4 form: add validator for alternative email or secret question”

AJAX request with Symfony sfBrowser in Lime functional test

Hello Symfonians!
While doing functional tests for my current Symfony application I needed to make AJAX call to one of my project endpoint.
I have found that not Lime or sfBrowser have this ability out of the box.
So if you need to make AJAX request from your Lime functional test you need do the following in your test:
<?php
include(dirname(__FILE__) . '/../../bootstrap/functional.php');

$browser = new sfTestFunctional(new sfBrowser());
$limeTest = $browser->test();

$browser->setHttpHeader("X-Requested-With", "XMLHttpRequest");

$browser->post('/ajax/uri', array('param_name' => 'param_value'))->
with('request')->begin()->
isParameter('module', 'someModule')->
isParameter('action', 'someAction')->
end()->

with('response')->begin()->
isStatusCode(200)->
end();
?>

 

The key point is in the headers, you send to the server:
$browser->setHttpHeader(“X-Requested-With”, “XMLHttpRequest”);

Symfony sfAssetsLibraryPlugin assets resize script

Hi there!

I’d like to share with this pretty simple script with you, hope it will save you few minutes.

You guys who familiar with this Symfony plugin for assets management probably know that it uses sfThumbnail plugin for making thumbnails of image assets.
sfThumbnail has configuration in app.yml and it looks like:

all:
  sfAssetsLibrary:
    upload_dir:       media                  # Asset library root, under the web/ dir
    check_type:       false                  # Set to true if you want to restrict the type of assets
    types:            ['image']  # Accepted asset types if check_type is true
    thumbnail_dir:    thumbnail              # Where the image thumbnails are stored
    use_ImageMagick:  false                  # Set to true if you have the convert command
    thumbnails:                              # Name and size (in pixels) of the thumbnails created at upload
      tiny:                                 # Displayed in the list page
        width: 70
        height: 70
      small:                                 # Displayed in the list page
        width: 100
        height: 100
        shave: false                          # Cut strips to constraint the image size
      middle:
        width: 200
        height: 200
      large:                                 # Displayed in the details page
        width: 450
        height: 450
      original:                                 # Displayed in the details page
        width: 800
        height: 800
    search_pager_size: 20                    # Number of resuts per page
    mass_upload_size:  5                     # Number of file upload controls displayed in the mass upload form

This is cool but when you have your project up and running and decided to add new type of thumbnail (for instance name it ‘big’)

      big:
        width: 400
        height: 400
you’ll have a problem: you need to resize all old images according to new thumbnail type.

Continue reading “Symfony sfAssetsLibraryPlugin assets resize script”