遵循此文档
https://sonata-project.org/bundles/admin/master/master/doc/cookbook/recipe_virtual_field.field.html
我尝试做这个
<?php
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
.....
->add('tancar', 'checkbox',array(
'virtual_field' => true
))
有此错误
不存在选项" Virtual_field"。定义的选项是:"操作"," allow_extra_fields"," attr"," auto_initialize"," block_name"," by_reference"," grop","复合","约束"," csrf_field_name","," csrf_token_manager"," data"," data_class"," disabled"," empty_data"," error_bubbling"," error_mapping"," extra_fields_message"," extrace_fields_message"," forex_intal_input_input_wrapper_prapper_class"," Invalid_message"," Invalid_message_parameters"," label"," label_attr"," label_format"," label_render","映射","方法"," post_max_size_size_message","," sonata_help"," translation_domain"," trim"," upload_max_size_message"," validation_groups"," value"。
怎么了?
您可以尝试以下方法:
->add('_action', null, [
'virtual_field' => true,
'actions' => [
'edit' => [],
'delete' => [],
],
]);
因为virtual_field
适用于_action
或batch
。在文档中"包括各个映射器在内的某些字段不依赖于模型中的任何实际字段(例如,_ATCONT或批次)。"
似乎要在ListMapper中使用此选项,我已经解决了在实体中创建此方法的方法:
<?php
public function getTancar()
{
return false;
}
public function setTancar($value)
{
}
然后,我可以在控制器或admin类中获取此参数(例如,Update方法)