0
votes

in symfony sonata :

  • I have an object CONTACT contains many ROLE -

i want to see all was inside an entity role in form mapper: my entity role have 4 parameters. (label function, phone, email, etc...)

actually i just have a link to the object. (but i want to see all the parameters was inside the entity)

i try this in my form mapper of my class ADMIN

 $showMapper
           ->with('CONTACT - FUNCTION')
           ->add('role')
           ->end()

namespace AdminBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;

/**
 * Role
 */
class Role
{
    /**
     * @var int
     */
    private $id;

    /**
     * @var string(unique=true)
     */
    private $function;

    /**
     * @var int
     */
    private $organisation;

    /**
     * @var string
     */
    private $phone;

    /**
     * @var string
     */
    private $email;

     /**
     * @var int
     */
    private $contact=null;

    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }


    public function __toString(){
    return sprintf("%s %s", $this->getFunction(), $this->getOrganisation());
    }

    public function getFunction_name()
    {
    return $this->getFunction();
    }




     /**
     * Set contact
     *
     * @param int $contact
     *
     * @return role
     */
    public function setContact($contact)
    {
        $this->contact = $contact;

        return $this;
    }

    /**
     * Get contact
     *
     * @return int
     */
    public function getContact()
    {
        return $this->contact;
    }


    /**
     * Set function
     *
     * @param string $function
     *
     * @return Role
     */
    public function setFunction($function)
    {
        $this->function = $function;

        return $this;
    }

    /**
     * Get function
     *
     * @return string
     */
    public function getFunction()
    {
        return $this->function;
    }

    /**
     * Set organisation
     *
     * @param int $organisation
     *
     * @return Role
     */
    public function setOrganisation($organisation)
    {
        $this->organisation = $organisation;

        return $this;
    }

    /**
     * Get organisation
     *
     * @return int
     */
    public function getOrganisation()
    {
        return $this->organisation;
    }

    /**
     * Set phone
     *
     * @param string $phone
     *
     * @return Role
     */
    public function setPhone($phone)
    {
        $this->phone = $phone;

        return $this;
    }

    /**
     * Get phone
     *
     * @return string
     */
    public function getPhone()
    {
        return $this->phone;
    }

    /**
     * Set email
     *
     * @param string $email
     *
     * @return Role
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

}

and my doctrine file

AdminBundle\Entity\Role:
    type: entity
    table: null
    repositoryClass: AdminBundle\Repository\RoleRepository
    id:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
    fields:
        function:
            type: string
            length: 100
            unique: true
        phone:
            type: string
            length: 100
            nullable: TRUE
        email:
            type: string
            length: 100
            nullable: TRUE
    manyToOne:
        organisation:
            targetEntity: AdminBundle\Entity\Organisation
            joinColumn:
                name: organisation
                referencedColumnName: id
            nullable: TRUE
    manyToMany:
        contact:
            targetEntity: AdminBundle\Entity\Contact
            joinTable:
                name: allrole
                joinColumns:
                    role:
                        referencedColumnName: id
                inverseJoinColumns:
                    contact:
                        referencedColumnName: id
1

1 Answers

0
votes

Create a __toString() method into your Role entity with properties you want to display.

public function __toString()
{
    return (string) "Function: " . $this->function . ", Phone: " . $this->phone . ", Email: " . $this->email;
}