我已经安装了Sonata管理员,媒体,分类和其他一些没有任何问题的人。 我有一个名为task的实体,我需要能够将一些文件附加到我的任务中。所以我的Task实体看起来像这样:
class Task {
//...
/**
* @ORM\OneToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media")
* @ORM\JoinColumn(name="attachment_id", referencedColumnName="id")
**/
protected $attachment;
//...
}
在我的TaskAdmin.php中我有
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
//...
->add('attachment', 'sonata_media_type', array(
'provider' => 'sonata.media.provider.image',
'context' => 'default'
));
}
这是MediaBUndle的config.yml设置:
sonata_media:
default_context: default
db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr
contexts:
default: # the default context is mandatory
providers:
- sonata.media.provider.dailymotion
- sonata.media.provider.youtube
- sonata.media.provider.image
- sonata.media.provider.file
formats:
small: { width: 100 , quality: 70}
big: { width: 500 , quality: 70}
cdn:
server:
path: /uploads/media # http://media.sonata-project.org/
filesystem:
local:
directory: %kernel.root_dir%/../web/uploads/media
create: false
现在,当我尝试创建新任务时,http://myweb.dev/app_dev.php/admin/core/task/create)I会收到以下错误:
Neither the property "attachment" nor one of the methods "getAttachment()", "attachment()", "isAttachment()", "hasAttachment()", "__get()" exist and have public access in class "CoreBundle\Entity\Task".
知道我做错了什么吗? 提前谢谢。
答案 0 :(得分:3)
您的任务实体必须具有包含getter和setter的附件字段。例如:
protected $attachment;
public function getAttachment()
{
return $this->attachment;
}