奏鸣曲管理员无法识别选择选项
Sonata admin doesn't recognize choices option
我正在尝试实现一个过滤器,它将select以下状态之一:
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()])
这是我在Whosebug上找到的一种方法。但是,每当我执行代码时,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 select 或类似的东西 select 5 个值之一吗?
有一个特定的 ChoiceType 字段,而不是您使用的 FormType 字段。
您可以玩多个和扩展以交替使用复选框、单选按钮或 select。
请参阅文档:
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 的信息。也许它不适用于奏鸣曲。但是 Sonata doc 说要这样做:
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Sonata\AdminBundle\Admin\AbstractAdmin;
final class PageAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('multiChoices', ChoiceType::class, [
'multiple' => true,
'sortable' => true,
])
;
}
}
我正在尝试实现一个过滤器,它将select以下状态之一:
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()])
这是我在Whosebug上找到的一种方法。但是,每当我执行代码时,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 select 或类似的东西 select 5 个值之一吗?
有一个特定的 ChoiceType 字段,而不是您使用的 FormType 字段。 您可以玩多个和扩展以交替使用复选框、单选按钮或 select。 请参阅文档:
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 的信息。也许它不适用于奏鸣曲。但是 Sonata doc 说要这样做:
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Sonata\AdminBundle\Admin\AbstractAdmin;
final class PageAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('multiChoices', ChoiceType::class, [
'multiple' => true,
'sortable' => true,
])
;
}
}