Note that there are some explanatory texts on larger screens.

plurals
  1. POretrieve the Many side of association in Doctrine2
    primarykey
    data
    text
    <p>I have two entities one is Role and other is User , I want to build forms and reports to add and show each role with their users , and to create a user with one Role so its User:Role (One-To-Many), I managed to add role to a user via Doctrine 2 but I cannot show users fro each role below is my code </p> <pre><code>&lt;?php /** * Description of Role * @Entity * @Table=(name"Roles") * @author alaaqashou */ class Role { //put your code here /** * * @var integer $id * @Column(name="id", type="integer",nullable=false) * @Id * @GeneratedValue(strategy="IDENTITY") */ private $id; /** * @Column(length=100,nullable=false,unique=true) * @var type */ private $name; /** * @OneToMany(targetEntity="User" ,mappedBy="Role") * @var type */ private $users; public function __construct() { $this-&gt;users=new \Doctrine\Common\Collections\ArrayCollection(); } public function getUsers() { return $this-&gt;users; } public function setUsers($user) { $this-&gt;users-&gt;add($user); } } /** * Description of User *@Entity * @Tabel(name="Users") * @author alaaqashou */ class User { //put your code here /** * * @var integer $id * @Column(name="id", type="integer",nullable=false) * @Id * @GeneratedValue(strategy="IDENTITY") */ private $id; /** * * @Column(length=255,nullable=false,unique=true) * * * @var type * */ private $role; function __construct() { $this-&gt;created=new \DateTime(date("Y-m-d H:i:s")); } public function getRole() { return $this-&gt;role; } public function setRole($role) { $this-&gt;role = $role; } } </code></pre> <p>I got the Notice: Undefined index: Role error when I try to do the following </p> <p>my Service</p> <pre><code> public function listAllRole() { return $this-&gt;em-&gt;getRepository('sihha\Entity\Role')-&gt;findAll(); } $roles=$this-&gt;roleService-&gt;listAllRole(); $users=$roles[0]-&gt;getUsers(); // I even tried $users=$roles[0]-&gt;getUsers()-&gt;toArray(); $user=$users[0]; </code></pre> <p>Please Help!!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload