奏鸣曲管理员无法识别选择选项

时间:2019-09-09 12:09:48

标签: symfony sonata-admin

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

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 select或类似方法选择5个值之一吗?

1 个答案:

答案 0 :(得分:2)

有一个特定的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 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,
            ])
        ;
    }
}

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