简体   繁体   English

奏鸣曲创建实体管理仪表板

[英]sonata create entity admin dashboard

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"? 为什么是“: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

To prevent sonata from showing 0000000037b8f75700000000ca0fce3d you need to add toString methode to your entities. 为了防止奏鸣曲显示0000000037b8f75700000000ca0fce3d,您需要向实体添加toString方法。 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. 对于仪表板链接的问题,您可以在config.yml中向我显示仪表板配置吗,我认为您使用的是同一服务。 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. 最后,如果Sonata返回错误消息,则必须检查逻辑,这意味着您必须在表单提交事件之后检查Assert并检查对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM