A typical Developer Blog
by Gordon Franke
Icon

Change from Doctrine to Doctrine_Core with one command

To change all your code from Doctrine to Doctrine_Core you can use the following command

1
for fl in `find apps/ config/ lib/ test/ -name *.php`; do mv $fl $fl.old; sed 's/Doctrine::/Doctrine_Core::/g' $fl.old > $fl; rm -f $fl.old; done

When you have a plugin you can use this command

1
for fl in `find . -name *.php`; do mv $fl $fl.old; sed 's/Doctrine::/Doctrine_Core::/g' $fl.old > $fl; rm -f $fl.old; done

How can i use embed forms or simgle form fields depend on a form field?

You have a register form with a field account_type and two embed forms Company and Address.

You want remove the embed Company form, when the field account_type is sfGuardUserProfile::TYPE_PRIVATE otherwise you want remove the embed Address form.

The solution is to override the bind method in your form.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  public function bind(array $taintedValues = null, array $taintedFiles = null)
  {
    // unset request param and validator
    if($taintedValues['account_type'] == sfGuardUserProfile::TYPE_PRIVATE)
    {
      unset(
        $taintedValues['Company'],
        $this->validatorSchema['Company']
      );
    }
    else
    {
      unset(
        $taintedValues['Address'],
        $this->validatorSchema['Address']
      );
    }
 
    parent::bind($taintedValues, $taintedFiles);
  }

How can i check the count of database queries in my unit test?

1
2
3
$manager    = new sfDatabaseManager($configuration);
$connection = $manager->getDatabase('doctrine')->getDoctrineConnection();
$connection->count();

How can i call a symfony event from doctrine model?

1
2
$dispatcher = sfProjectConfiguration::getActive()->getEventDispatcher();
$dispatcher->notify($event);