我想做的是为表单中的每一行注入一个唯一的id。使用sfWidgetFormSchemaFormatter可以很容易地自定义表单布局,但不能为一行注入唯一的id。
基本上想做这样的事情:
<?php
class sfWidgetFormSchemaFormatterCustom extends sfWidgetFormSchemaFormatter {
protected
$rowFormat = "<div id='"row_%form_field_name%'">%error% 'n %label% 'n %field%%help% %hidden_fields%</div>'n",
}
这似乎是一个直观的功能,但在API和讨论中大量涌现,还没有发现有人这样做的例子。这将使交互式表单更加容易。
class sfWidgetFormSchemaFormatterTwitterBootstrap extends sfWidgetFormSchemaFormatter
{
// ...
// here is some your code
// ...
public function __construct(sfWidgetFormSchema $widgetSchema)
{
foreach ($widgetSchema->getFields() as $field) {
if (get_class($field) == 'sfWidgetFormInputText') {
$field->setAttribute('id', 'whatever-id');
}
}
parent::__construct($widgetSchema);
}
// ...
// here is some your code
// ...
}
在这里,您可以遍历所有表单元素并检查所有参数。当我的Twitter引导格式化程序从TB2迁移到TB3.0时,我确实喜欢这样——它们需要为每个输入字段提供字段类"表单控制"。以下是我的做法:http://www.alexfilatov.com/2014/01/07/symfony-1-4-twitter-bootstrap-3-0-form-formatter/