Skip to content

colocar un item por defecto a un combo relacionado

  1. //MenuCardTable.class
  2. public function getMenuCardForCombo(){
  3.         $q = Doctrine_Query::create()
  4.           ->select(‘m.*’)
  5.           ->from(‘MenuCard m’);
  6.         $results = $q->execute();
  7.         foreach($results as $menu){
  8.             $choice[$menu->getId()] = $menu->getName();
  9.         }
  10.         return $choice;
  11.     }
  12. ====================no funciona para validar “required”=========================================
  13. //DishesForm.class
  14.         $choices = array(‘Seleccione un item’) + Doctrine::getTable(‘MenuCard’)->getMenuCardForCombo();
  15.         $this->widgetSchema[‘menu_card_id’] = new sfWidgetFormSelect(array(‘choices’ => $choices));
  16.         $this->validatorSchema[‘menu_card_id’] = new sfValidatorChoice(array(‘choices’ => array_keys($choices)));
  17. ====================otro metodo: validar “required”=========================================
  18. //el item x defecto sera en blanco (poner ‘add_empty true’)
  19. //BasesDishesForm.class
  20. ‘menu_card_id’ => new sfWidgetFormDoctrineChoice(array(‘model’ => ‘MenuCard’, ‘add_empty’ => true)),
  21. //DishesForm.class
  22. $this->validatorSchema[‘menu_card_id’]->setOption(‘required’, true);