Thursday, June 24, 2010

Password Confirmation Widget and Validator in Symfony

$this->widgetSchema['password'] = new sfWidgetFormInputPassword(array('label' => 'Password'));
$this->widgetSchema['password_confirm'] = new sfWidgetFormInputPassword(array('label' => 'Password confirm'));
$this->validatorSchema['password'] = new sfValidatorString(array(
  'min_length' => 5
), array(
  'min_length' => 'Password too short (min 5 chars).'));
$this->validatorSchema['password_confirm'] = clone $this->validatorSchema['password'];
sfValidatorSchemaCompare::EQUAL, 'password_confirm', array(),
array('invalid' => 'Passwords do not match.')));
Note: In this case password fields are not required.

Wednesday, June 23, 2010

Create MySQL Dump to Save Data Before doctrine:build

If you use the symfony doctrine:build --all command, all data will be deleted in the database. To fix this, you have to save the data before the building and then import the dump file...
  1. mysqldump -t -c -u root -p DBNAME > dump.sql
  2. symfony doctrine:build --all
  3. mysql -u root -p DBNAME < dump.sql
Note: On Windows, you have to add the path (the mysql/bin directory) to the environmental variables.
Note2: The -t parameter removes the drop table and create table queries from the dump. It is needed if you change the structure of a table, otherwise drop table query will delete what symfony doctrine:build created.
Note3: The -c parameter adds the column names to INSERT INTO statements.

Tuesday, June 22, 2010

Enable mod_rewrite in Apache 2

Use the a2enmod rewrite command to enable mod_rewrite in Apache2, then restart the webserver with: /etc/init.d/apache2 restart

Monday, June 21, 2010

Symfony String Validator

$this->validatorSchema['subject'] = new sfValidatorString(array(
  'required' => true,
  'max_length' => 255
), array(
  'required' => 'Required field.',
  'max_length' => 'Too long, maximum 255 characters.'

Vertical Align in DIV

The container div must have these CSS properties:

display: table-cell;
vertical-align: middle;

and the child elements (img, div, span) must have only the vertical-align: middle; property.

Note: The container div mustn't have a float value!