2017-09-10 7 views
1

J'ai un problème sous forme de charge dans le service Symfony 3.2 i créé champ personnalisé comme:formulaire que le service ne fonctionne pas

class ImageType extends AbstractType 
{ 
    private $path; 

    /** 
    * ImageType constructor. 
    */ 
    public function __construct($path) 
    { 
     $this->path = $path; 
    } 

    /** 
    * @return string 
    */ 
    public function getParent() 
    { 
     return FileType::class; 
    } 

    /** 
    * @return string 
    */ 
    public function getName() 
    { 
     return 'image'; 
    } 

    /** 
    * @param OptionsResolver $resolver 
    */ 
    public function configureOptions(OptionsResolver $resolver) 
    { 
     $resolver->setDefaults(array(
      'image_name' => '' 
     )); 
    } 

    /** 
    * @param FormView $view 
    * @param FormInterface $form 
    * @param array $options 
    */ 
    public function buildView(FormView $view, FormInterface $form, array $options) 
    { 
     $view->vars['image_name'] = $options['image_name']; 
    } 

    /** 
    * @param FormBuilderInterface $builder 
    * @param array $options 
    */ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 

     $builder 
      ->setAttribute('image_name', $options['image_name']) 
      ->addModelTransformer(new ImageTransformer($this->path)); 
    } 
} 

et service.yml:

services: 
    app.form_image_type: 
     class: AppBundle\Form\Type\ImageType 
     arguments: ['%upload_directory%'] 
     tags: [form.type] 

Mais quand je lance le code I ont une erreur:

2/2 FileLoaderLoadException in FileLoader.php line 118: A "tags" entry must be an array for service "app.form_image_type" in /var/www/exammple.pl/app/config/services.yml. Check your YAML syntax in /var/www/example/app/config/services.yml (which is being imported from "/var/www/example.pl/app/config/config.yml"). 1/2 InvalidArgumentException in YamlFileLoader.php line 270: A "tags" entry must be an array for service "app.form_image_type" in /var/www/example.pl/app/config/services.yml. Check your YAML syntax.

Mais selon docs, les balises sont définies correctement, alors avez-vous résolu ce problème?

+0

Vous regardez les documents 3.3 dans lequel la syntaxe de la balise a été simplifiée. Passez à la doc 3.2 et suivez l'exemple. – Cerad

Répondre

3

essayer avec ce code:

tags: 
    - { name: form.type } 

regard sur doc avec la version 3.2