我有負載的形式問題,因爲在Symfony的3.2服務,我創建的自定義字段:形式服務無法正常工作
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));
}
}
和service.yml:
services:
app.form_image_type:
class: AppBundle\Form\Type\ImageType
arguments: ['%upload_directory%']
tags: [form.type]
但是當我運行的代碼,我有錯誤:
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.
但根據文檔,標籤定義得當,所以已經解決了這個問題?
您正在尋找在3.3文檔中的標記語法進行了簡化。切換到3.2文檔並按照示例進行操作。 – Cerad