Reputation: 351
I've installed Sonata Admin, Media, Classification, and few others without any problem. I have an entity called task and I need to be able to attach some files to my tasks.So my Task entity looks like this:
class Task {
//...
/**
* @ORM\OneToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media")
* @ORM\JoinColumn(name="attachment_id", referencedColumnName="id")
**/
protected $attachment;
//...
}
and in my TaskAdmin.php I have
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
//...
->add('attachment', 'sonata_media_type', array(
'provider' => 'sonata.media.provider.image',
'context' => 'default'
));
}
And here is the config.yml settings for MediaBUndle:
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
Now when I try to create a new task (http://myweb.dev/app_dev.php/admin/core/task/create)I get the following error:
Neither the property "attachment" nor one of the methods "getAttachment()", "attachment()", "isAttachment()", "hasAttachment()", "__get()" exist and have public access in class "CoreBundle\Entity\Task".
Any idea what I'm doing wrong? Thanks in advance.
SonataUserBundle - Neither property nor methods exist
Upvotes: 1
Views: 673
Reputation: 856
Your task entity must have an attachment field with getters and setters. For example:
protected $attachment;
public function getAttachment()
{
return $this->attachment;
}
Upvotes: 3