我想将数据表单configureFormFields()方法传递给Twig文件,我使用formMapper在twig文件中使用该数据.我使用Sonata Admin和Overwrite默认模板以及自定义视图模板.以下是我的代码:
控制器代码:
protected function configureFormFields(FormMapper $formMapper)
{
$container = $this->getConfigurationPool()->getContainer();
$entityManager = $container->get('doctrine.orm.entity_manager');
$subject = $this->getSubject();
$formMapper->add('fieldValue',NumberType::class,array('label'=>'Other Country','required'=>true))->add('id','hidden',array('data' =>'1'));
}
Run Code Online (Sandbox Code Playgroud)
Twig文件视图代码:
<div class="col-lg-12 col-ms-12 col-sm-12">
<div class="col-lg-12 col-ms-12 col-sm-12">
<h3>For Others Country</h3>
</div>
<div class="col-lg-12 col-ms-12 col-sm-12">
<div class="form-group {% if form_errors(form.fieldValue) %}has-error{% endif %}">
{{ form_label(form.fieldValue, 'Other Country'|trans, {'label_attr': {'class': 'control-label'}}) }}<span class="asterik"></span>
{{ form_widget(form.fieldValue, {'attr': {'class': 'form-control phonecode_field','data-placeholder':'Other Country'|trans}}) }}
<span class="help-block {% if form_errors(form.fieldValue) %}has-error{% endif %}">{{ form_errors(form.fieldValue) }}</span>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我设置了fieldValue文本框的值和来自控制器的Pass值,以便它可以如何实现?