索纳塔管理员无法识别选项选项



我正在尝试实现一个过滤器,该过滤器将选择以下状态之一:

public const OPEN                  = 'open';
public const READY_FOR_EXECUTION   = 'ready_for_execution';
public const IN_PROGRESS           = 'in_progress';
public const PAYOUT                = 'payout';
public const ARCHIVED              = 'archived';

我尝试按如下方式实现过滤器:

$filter->add('type', 'doctrine_orm_choice', ['label' => 'Status'], null, ['choices' => Status::getValues()])

这是我在Stackoverflow上找到的一种方式。但是,每当我执行代码时,Symfony都会抛出500服务器错误:

The option "choices" does not exist. Defined options are: "action", "allow_extra_fields", "allow_file_upload", "attr", "attr_translation_parameters", "auto_initialize", "block_name", "block_prefix", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "field_wrapper_attr", "help", "help_attr", "help_html", "help_translation_parameters", "horizontal_input_wrapper_class", "horizontal_label_class", "horizontal_label_offset_class", "inherit_data", "input_wrapper_attr", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "label_raw", "label_render", "label_translation_parameters", "mapped", "method", "post_max_size_message", "property_path", "required", "sonata_admin", "sonata_field_description", "sonata_help", "tooltip", "translation_domain", "trim", "upload_max_size_message", "validation_groups".

显然这种方法不起作用,文档对此也不是很清楚。有人可以向我解释如何创建一个过滤器,让用户通过 html 选择或类似的东西选择 5 个值之一吗?

有一个特定的 ChoiceType 字段,而不是您使用的 FormType 字段。 您可以使用多个和展开来播放,以交替使用复选框、单选按钮或选择。 请参阅文档:

https://symfony.com/doc/3.4/reference/forms/types/choice.html 例:

$form = $this->createFormBuilder()
->add('_', ChoiceType::class, array(
'choices' => [
'yes' => true,
'no' => false,
'maybe' => null,
],
'multiple' => true,
'expanded' => false,
'label_attr' => array('class' => 'checkbox-inline'),
))

编辑:

我给了你基于symfony的信息。也许它不适用于奏鸣曲。但是奏鸣曲文档说要这样做:

use SonataAdminBundleFormFormMapper;
use SymfonyComponentFormExtensionCoreTypeChoiceType;
use SonataAdminBundleAdminAbstractAdmin;
final class PageAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('multiChoices', ChoiceType::class, [
'multiple' => true,
'sortable' => true,
])
;
}
}

来源:https://symfony.com/doc/current/bundles/SonataAdminBundle/reference/form_types.html#symfonycomponentformextensioncoretypechoicetype

最新更新