Symfony 1.4 multi fields validator

In your form class (lib/form/doctrine/classForm.class.php)

  $this->validatorSchema->setPostValidator(
      new sfValidatorMultiFields(
        array('field1', 'field2', 'field3'),
        array('labels' => array('name1', 'name2', 'name3')),
        array('global_invalid' => 'Multi fields error')));

save this class in a lib folder, for exemple apps/frontend/lib/sfValidatorMultiFields.class.php

<?
class sfValidatorMultiFields extends sfValidatorSchema
{
 
  public function __construct(array $fields, $options = array(), $messages = array())
  {
    $this->addOption('fields', $fields);

    $this->addMessage('invalid', 'Error with this field');
    $this->addMessage('global_invalid', 'Multi fields error');

    parent::__construct(null, $options, $messages);
  }

  protected function doClean($values)
  {
    $valid = false;
    foreach ($this->getOption('fields') as $field) {
	//put here your validation code
        // ex: $values[$field] ....
    }
    //another example, at least one field in not empty
    if($values['field1'] != '' || $values['field2'] != '' || $values['field3'] != '')
    {
        $valid = true;
    }

    if ($valid)
    {
      $errorSchema = new sfValidatorErrorSchema($this);

        // The global error
        $errorSchema->addError(new sfValidatorError($this, 'global_invalid', array()));
      }

      // Fields error
      $error = new sfValidatorError($this, 'invalid', array()));

      // Add the error for each defined fields
      foreach ($this->getOption('fields') as $field)
      {
        $errorSchema->addError($error, $field);
      }

      throw $errorSchema;
    }

    return $values;
  }
}
?>

The keys points are :
– use $this->validatorSchema->setPostValidator() in your form class
– all fields are now available from the $values array ($values[‘field1′], $values[‘field2′] …)

Magento – display more than one image on page list

If you need to pull out more than one image per product in page list (list.phtml), the code below will help you.

<?php
  //get more images for product
  $product = Mage::getModel('catalog/product')->load($_product->getId());
  foreach ($product->getMediaGalleryImages() as $image) {
     echo "<img src='" . $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $image->getFile())->resize(50) . "' />";
  }
?>

Remove index.php from URL .htaccess

How to remove index.php from URL using .htaccess file ?
That is this easy :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteRule ^index\.php(.+) $1 [R=301,L]
</IfModule>

Maybe you are using a magento website and you need to keep index.php for the backoffice.
Then add this condition to the .htaccess file

RewriteCond %{REQUEST_URI} !^[^/]*/index\.php/admin.*

and don’t forget to enable rewrite module

a2enmod rewrite