I installed the Sonata Admin bundle for manage an online library. I just wanted to link an image
to an author
.
The mapping is correct : [Mapping] OK - The mapping files are correct. [Database] OK - The database schema is in sync with the mapping files.
This is the field of my author
entity :
/**
*
* @ORM\Column(name="image", type="string", length=255)
* @ORM\OneToOne(targetEntity="Project\BackendBundle\Entity\Image", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $image;
I create an Admin class for each entity :
ImageAdmin.php works correctly. When I add a new image, the database is updated and the image is uploaded.
Then I create the AuthorAdmin thanks to the documentation ( http://sonata-project.org/bundles/admin/master/doc/reference/form_types.html#sonata-type-admin ).
AuthorAdmin.php
class AuthorAdmin extends Admin
{
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', 'text', array('label' => 'Author name'))
->add('image', 'sonata_type_admin')
;
}
// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('name')
;
}
// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('name')
;
}
}
But i always have this message :
The current field
image
is not linked to an admin. Please create one for the target entity : ``
The admins are set in the admin.yml :
services:
sonata.admin.author:
class: Project\BackendBundle\Admin\AuthorAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Content", label: "Author" }
arguments:
- ~
- Project\BackendBundle\Entity\Author
- ~
sonata.admin.image:
class: Project\BackendBundle\Admin\ImageAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Content", label: "Image" }
arguments:
- ~
- Project\BackendBundle\Entity\Image
- 'SonataAdminBundle:CRUD'
I followed all the documentation but now I don't see the problem.
Your mapping is not correct. There should not be such line.
@ORM\Column(name="image", type="string", length=255)
@ORM\\Column
overrides @ORM\\OneToOne
and Doctrine sees this field as simple field - not as association.
http://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html#annref-onetoone
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.