2012-07-12 66 views
0

部分listForm.class.php:embedForm額外字段隱藏我的代碼

public function configure() { 
    $list_id = $this->getOption('list_id'); 
    $endkunde_id = $this->getOption('endkunde_id'); 
    $shopname_id = 1; 


    $todoWrapperForm = new sfForm(); 
    $todoWrapperForm = new sfForm(); 
    //$todos = Doctrine_Core::getTable('Todo')->findAll(); 


    //$todos = Doctrine_Core::getTable('EinkaufslisteElemente')->findAll(); 
    $todos = Doctrine_Core::getTable('EinkaufslisteElemente') 
      ->createQuery('ee') 
      ->where('ee.einkaufsliste_id = ?', $list_id) 
      ->innerJoin('ee.Einkaufsliste e') 

      ->andWhere('e.shopname_id = ?', $shopname_id) 
      ->innerJoin('e.EinkaufslisteEndkunde ek') 
      ->execute(); 


    foreach ($todos as $todo) { 
     $todoWrapperForm->embedForm($todo->getId(), new EinkaufslisteElementeForm($todo)); 
    } 
    $todoWrapperForm->embedForm('new_1', new EinkaufslisteElementeForm()); // add one blank todo to start 
    $this->embedForm('todos', $todoWrapperForm); 


     $this->list = new sfWidgetFormTextarea(array(), array('rows' => '10', 'cols' => '35')); 

    $this->mergePostValidator(new sfValidatorDoctrineUnique(array('model'=>'todo', 'column'=>'task'), array('required' => false)))    ; 
    $this->widgetSchema->setNameFormat('todo_list[%s]'); 
} 

我想創建一個從他的名字「客戶」,這是不是隱藏着一個額外的領域,我想創建一個輸入字段用List'List'中的list_id隱藏。我怎麼用embedForm做到這一點?

+0

你爲什麼想在你的'embedForm'中做到這一點?由於它與listForm相關,因此將其放入內部。 – j0k 2012-07-12 10:30:14

+0

那我怎麼把它放進去呢? – craphunter 2012-07-12 10:31:17

+0

使用sfWidgetFormInputHidden? – j0k 2012-07-12 10:35:14

回答

2

裏面你listForm,只需添加在你配置的底部:

$this->widgetSchema['list_id'] = new sfWidgetFormInputHidden(); 
// do not forget to add the propel validator (ie: the one that can check if `list_id` is ok - like in the database) 
$this->validatorSchema['list_id'] = new sfValidatorPass(); 

然後,在你的行動,不要忘了一個默認設置爲list_id

$form = new listForm(); 
$form->setDefault('list_id', $list_id); 
+0

我沒有考慮創建一個新的表單!其實很簡單! symfony的美麗。謝謝! – craphunter 2012-07-12 15:21:33