2014-02-28 51 views
0

我有這樣的形式:Symfony的形式和迭代器輸入複選框/文本

->add('task', 'text') 
->add('dueDate', 'date') 
->add('save', 'submit') 

我想迭代使用來自數據庫的數據的輸入文本/複選框。

換句話說,我想根據數據庫中的數據打印字段。 像一個foreach,但所有使用的形式symfony($結果爲$ val){print'input type =「checkbox」value =「valore」'}

你能幫助我嗎?

+0

請說明您的問題和** **問一個真正的問題。 –

+0

@AndrzejOśmiałowski更新! thx – user3037814

+0

您是否想過嵌入式表單的集合?網址:http://symfony.com/doc/current/cookbook/form/form_collections.html。 –

回答

0

可能是你正在尋找的形式製作工具的詳情:http://symfony.com/doc/current/book/forms.html#building-the-form

//In your controller 
$results = //get data from the database here 

$form = $this->createFormBuilder(); 

foreach($results as $result){ 
    $form->add($result['field_name'],$result['field_type'],array('data=>$result['field_value']')); 

    //Where field_name would be something like task, dueDate, save, etc. 
    // field_type would be something like, text, choice, hidden 
    //then to set the data for the field you pass it in the data option aka field_value 
} 

$form->getForm()->createView;