【发布时间】:2015-12-12 15:38:34
【问题描述】:
我尝试使用我自己的 ImageType 配置 EasyAdminBundle 以在我的 ArticleType 中上传文件。
所以我在app\config\services.yml 创建了这个服务:
services:
oah_news_form_type_image:
class: OAH\NewsBundle\Form\ImageType
tags: [ { name: form.type, alias: 'oah_news_form_type_image' } ]
并尝试在我的app\config\config.yml 中调用它:
easy_admin:
entities:
Article:
class: OAH\NewsBundle\Entity\Article
form:
fields:
- Titre
- Auteur
- Date
- Categorie
- { property : 'Image', type : oah_news_form_type_image}
但我有以下错误,我不知道如何解决它:
The type name specified for the service "oah_news_form_type_image" does not match the actual name. Expected "oah_news_form_type_image", given "oah_newsbundle_image"
我的图像类型:
class ImageType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('file', 'file');
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'OAH\NewsBundle\Entity\Image'
));
}
/**
* @return string
*/
public function getName()
{
return 'oah_newsbundle_image';
}
}
谢谢!
【问题讨论】:
-
你使用哪个版本的 symfony? FormType 中有 getName() 方法吗?
-
我有 2.6.12 版本的 symfony。我编辑了我的第一篇文章以添加我的 ImageType