Reputation: 1505
I'm tryin to use sonata admin bundle.
I have in my dashboard my two entities: user and questionnaire
I have two link for the two entites, add new and list.
But if I click of list for questionnaire, I have the questionnaire list and when I click in user list, I have also questionnaire list (and not user list).
Another problem, when I click to add, I have a good form, but it is related to
questionnaireBundle\Entity\questionnaire:0000000037b8f75700000000ca0fce3d
why the ":0000000037b8f75700000000ca0fce3d"?
If I fill the form and click create, I have the error :
An error has occurred during the creation of item "questionnaireBundle\Entity\avance:000000001c934f6f00000000d6359d04".
What have I done?
My questionnaireAdmin:
<?php
namespace questionnaireBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class questionnaireAdmin extends Admin {
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper) {
$formMapper
->add('nom')
->add('nbreQuestions')
;
}
// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper) {
$datagridMapper
->add('nom')
->add('nbreQuestions')
;
}
// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper) {
$listMapper
->addIdentifier('nom')
->add('nbreQuestions')
;
}
}
My questionnaire entity:
<?php
namespace questionnaireBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* questionnaire
*
* @ORM\Table()
* @ORM\Entity
*/
class questionnaire {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=255)
*/
private $nom;
/**
* @var integer
*
* @ORM\Column(name="nbreQuestions", type="integer")
*
* @Assert\NotBlank(message="Veuillez entrer un nombre de questions.")
* @Assert\Type(type="integer")
*/
private $nbreQuestions;
/**
* Get id
*
* @return integer
*/
public function getId() {
return $this->id;
}
/**
* Set nom
*
* @param string $nom
* @return questionnaire
*/
public function setNom($nom) {
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string
*/
public function getNom() {
return $this->nom;
}
/**
* Set nbreQuestions
*
* @param integer $nbreQuestions
* @return questionnaire
*/
public function setNbreQuestions($nbreQuestions) {
$this->nbreQuestions = $nbreQuestions;
return $this;
}
/**
* Get nbreQuestions
*
* @return integer
*/
public function getNbreQuestions() {
return $this->nbreQuestions;
}
}
My config:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: @UserBundle/Resources/config/admin.yml }
- { resource: @questionnaireBundle/Resources/config/admin.yml }
My admin user service:
services:
sonata.admin.user:
class: UserBundle\Admin\UserAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Content", label: "User" }
arguments:
- ~
- UserBundle\Entity\User
- ~
calls:
- [ setTranslationDomain, [UserBundle]]
My admin questionnaire service:
services:
sonata.admin.questionnaire:
class: questionnaireBundle\Admin\questionnaireAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Content", label: "questionnaire" }
arguments:
- ~
- questionnaireBundle\Entity\questionnaire
- ~
calls:
- [ setTranslationDomain, [questionnaireBundle]]
my confi.yml:
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
# Your other blocks
Upvotes: 0
Views: 1251
Reputation: 630
To prevent sonata from showing 0000000037b8f75700000000ca0fce3d you need to add toString methode to your entities. For the problem of the dashboard links can you show me the dashboard configuration in your config.yml i think that you reffer to the same service in the configuration. Finaly if Sonata return an errors mesasge you have to check your logic , i mean that you have to check your Assert and check the object after the form submit event.
Upvotes: 2