Sylius:无法加载“app.form.type.slider”类型

时间:2016-10-18 12:48:47

标签: sylius symfony-2.8

表单类型服务无法定义,问题在哪里!!!

的appbundle /资源/配置/ routing.yml中:

app_slider_create:
path: /sliders/slider/new
methods: [GET, POST]
defaults:
    _controller: app.controller.slider:createAction
    _sylius:
        form: app.form.type.slider

的appbundle /资源/配置/ services.yml:

app.form.type.slider:
    class: AppBundle\Form\Type\add_img_sliderType
    tags:
                - { name: form.type, alias: app_slider }
    arguments: [@doctrine, @sylius.context.locale]

的appbundle /形式/类型/ add_img_sliderType.php:

<?php
namespace AppBundle\Form\Type;

use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\FileType;

class add_img_sliderType extends AbstractResourceType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        // Build your custom form!
       $builder
       ->add('lib', 'text', [
      'label' => 'Libélle',
      ])
      ->add('description', 'text', [
     'label' => 'Description',
      ])
     ->add('path',FileType::class, [
    'required' => true,
    'label' => 'Photo',
    ])
    ;
    }

    public function getName()
    {
        return 'app_slider';
    }


}

1 个答案:

答案 0 :(得分:2)

我认为您应该在路由标记中定义表单,而不是使用完整的表单名称。所以你的路由配置应该是:

app_slider_create:
    path: /sliders/slider/new
    methods: [GET, POST]
    defaults:
        _controller: app.controller.slider:createAction
        _sylius:
            form: app_slider

请告诉我是否有帮助;)