0
我有這種形式在我的symfony應用程序:如何刪除嵌入形式(集合域)標籤中的symfony
namespace MyNamespace\EntityBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class OrganizationType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// profession checkboxes imbrication
->add('professions', 'collection', array(
'type' => new ProfessionType(),
'allow_add' => true,// if unrecognized items are submitted to the collection, they will be added as new items
'allow_delete' => false,
'by_reference' => false, //in order that the adders are called.
'mapped' => true,
))
->add('name')
->add('siret')
->add('corporation')
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'MyNamespace\EntityBundle\Entity\Organization',
'csrf_protection' => true,
'csrf_field_name' => '_token_',
// a unique key to help generate the secret token
'intention' => 'organization_stuff',
));
}
/**
* @return string
*/
public function getName()
{
return 'organization';
}
}
這我如何呈現的形式,我的樹枝觀點:
<div>
{{ form_start(form, {'action': path('path_action'), 'method': 'POST'}) }}
{{ form_errors(form) }}
{{ form_row(form.professions.vars.prototype) }}
{{ form_row(form.name) }}
{{ form_row(form.siret) }}
{{ form_row(form.corporation) }}
{{ form_end(form) }}
</div>
正如你可以看到我有一個必需的名爲標籤__name__label__(位於表單頂部)以及提交按鈕上方的嵌入式表單標籤職業。
我該如何解決這個問題,或者自定義這種行爲?
注意:在我的樹枝上,如果我只使用{{ form_row(form.professions) }}
,我的professionType不顯示字段。 這是ProfessionType.php
代碼:
$builder
->add('production', 'checkbox', array('required' => false))
->add('transport', 'checkbox', array('required' => false))
->add('pumping', 'checkbox', array('required' => false))
;
你爲什麼不直接打電話給這樣的專業:{{form_row(form.professions)}}?還可以向我們展示ProfessionType的代碼? – jiboulex
@jiboulex看到我的編輯,我添加ProfessionType,並照顧我的筆記,如果我只添加'{{form_row(form.professions)}}',我的字段不會顯示在我的視圖中。 –