1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
   |  
  public function setup()
  {
    $this->setWidgets(array(
     ...
      'companies_list' => new sfWidgetFormDoctrineChoice(array('multiple' => false, 'model' => 'Company')),
     ...
    ));
 
    $this->setValidators(array(
     ...
      'companies_list'      => new sfValidatorDoctrineChoice(array('multiple' => false, 'model' => 'Company', 'required' => true)),
     ...
    ));
 
  public function updateDefaultsFromObject()
  {
    parent::updateDefaultsFromObject();
    ...
    if (isset($this->widgetSchema['companies_list']))
    {
      $this->setDefault('companies_list', $this->object->getCompanyId());
    }
    ...
  }
 
  protected function doSave($con = null)
  {
    ...
    $this->saveCompaniesList($con);
    ...
    parent::doSave($con);
  }
 
  public function saveCompaniesList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }
 
    if (!isset($this->widgetSchema['companies_list']))
    {
      // somebody has unset this widget
      return;
    }
 
    if (null === $con)
    {
      $con = $this->getConnection();
    }
 
    $this->object->setCompanyId($this->getValue('companies_list'));
 
  } | 
Partager