3
如果我在表單中嵌入表單類型集合。我已將allow_add設置爲true。如何覆蓋原型輸出。假設我想在每次添加的表格中包裝表單類型的集合。想象一下,我可以在jquery中使用原型輸出,但是從一開始就非常適合。作爲一個例子我收藏的類型是:如何覆蓋Symfony2中的原型渲染
class EmailShareType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add("shareName","text",array("label"=>"Recipient Name:"));
$builder->add("emailName", "email", array("label"=>"Recipient Email:","required" => true));
$builder->add("emailMessage", "textarea",array("label"=>"Enter email message", "max_length" => "4000"));
}
public function getName()
{
return 'emailShare';
}
}
所得原型呈現爲:
data-prototype="
<div>
<label class="required">__name__label__</label>
<div id="emailShareCollection_emailShares___name__">
<div>
<label for="emailShareCollection_emailShares___name___shareName" class="required">Recipient Name:</label>
<input type="text" id="emailShareCollection_emailShares___name___shareName" name="emailShareCollection[emailShares][__name__][shareName]" required="required" />
</div>
<div>
<label for="emailShareCollection_emailShares___name___emailName" class="required">Recipient Email:</label>
<input type="email" id="emailShareCollection_emailShares___name___emailName" name="emailShareCollection[emailShares][__name__][emailName]" required="required" />
</div>
<div>
<label for="emailShareCollection_emailShares___name___emailMessage" class="required">Enter email message</label>
<textarea id="emailShareCollection_emailShares___name___emailMessage" name="emailShareCollection[emailShares][__name__][emailMessage]" required="required" maxlength="4000"></textarea>
</div>
</div>
</div>"
我如何渡過這個輸出控制?
你必須重載形式的呈現。 你可以在這裏閱讀:http://symfony.com/doc/current/cookbook/form/form_customization.html – Lughino