2015-06-17 66 views
1

您好,我剛剛從CI遷移到Fuel ....我使用Fieldset類自動生成窗體的視圖....我面臨的問題是我有多種類型的表單模板,即我的一些模型使用twitter bootstrap水平內聯表單,其中儘可能少的模型使用自定義模板...我可以在form.php中設置單一類型的表單模板,我從fuel/core/config/form.php中複製到燃料/應用/配置/ form.php的如何管理fuelphp中的多個表單模板

這裏是形式模板的樣品返回的數組

return array(
// regular form definitions 
'prep_value'     => true, 
'auto_id'     => true, 
'auto_id_prefix'    => 'form_', 
'form_method'    => 'post', 
'form_template'    => "\n\t\t{open}\n\t\t<table>\n{fields}\n\t\t</table>\n\t\t{close}\n", 
'fieldset_template'   => "\n\t\t<tr><td colspan=\"2\">{open}<table>\n{fields}</table></td></tr>\n\t\t{close}\n", 
'field_template'    => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{field} <span>{description}</span> {error_msg}</td>\n\t\t</tr>\n", 
'multi_field_template'  => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{group_label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{fields}\n\t\t\t\t{field} {label}<br />\n{fields}<span>{description}</span>\t\t\t{error_msg}\n\t\t\t</td>\n\t\t</tr>\n", 
'error_template'    => '<span>{error_msg}</span>', 
'group_label'    => '<span>{label}</span>', 
'required_mark'    => '*', 
'inline_errors'    => false, 
'error_class'    => null, 
'label_class'    => null, 

// tabular form definitions 
'tabular_form_template'  => "<table>{fields}</table>\n", 
'tabular_field_template'  => "{field}", 
'tabular_row_template'  => "<tr>{fields}</tr>\n", 
'tabular_row_field_template' => "\t\t\t<td>{label}{required}&nbsp;{field} {error_msg}</td>\n", 
'tabular_delete_label'  => "Delete?", 

);

我想這樣多的表單模板,這樣我就可以自動生成其中使用$ fieldset-所需要的形式>形式() - > build函數...

有什麼如何做到這一點?

回答

0

是的。試試這個:

forge($ name ='default',$ config = array());

$article_form = Fieldset::forge('article',array(
// regular form definitions 
'prep_value'     => true, 
'auto_id'     => true, 
'auto_id_prefix'    => 'form_', 
'form_method'    => 'post', 
'form_template'    => "\n\t\t{open}\n\t\t<table>\n{fields}\n\t\t</table>\n\t\t{close}\n", 
'fieldset_template'   => "\n\t\t<tr><td colspan=\"2\">{open}<table>\n{fields}</table></td></tr>\n\t\t{close}\n", 
'field_template'    => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{field} <span>{description}</span> {error_msg}</td>\n\t\t</tr>\n", 
'multi_field_template'  => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{group_label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{fields}\n\t\t\t\t{field} {label}<br />\n{fields}<span>{description}</span>\t\t\t{error_msg}\n\t\t\t</td>\n\t\t</tr>\n", 
'error_template'    => '<span>{error_msg}</span>', 
'group_label'    => '<span>{label}</span>', 
'required_mark'    => '*', 
'inline_errors'    => false, 
'error_class'    => null, 
'label_class'    => null, 

// tabular form definitions 
'tabular_form_template'  => "<table>{fields}</table>\n", 
'tabular_field_template'  => "{field}", 
'tabular_row_template'  => "<tr>{fields}</tr>\n", 
'tabular_row_field_template' => "\t\t\t<td>{label}{required}&nbsp;{field} {error_msg}</td>\n", 
'tabular_delete_label'  => "Delete?", 
)); 
+1

正是我需要的東西Thanx @EmRa –