您好我想創建這樣的映射映射和樹枝模板
class Users
{
/**
* @var integer
*
* @ORM\Column(name="id_users", type="smallint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=100, nullable=true)
*/
private $name;
/**
*
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="UsersEmailAddresses", mappedBy="users")
* @ORM\JoinColumn(name="id_users", referencedColumnName="users_id")
*/
private $email;
和
class UsersEmailAddresses
{
/**
* @var integer
*
* @ORM\Column(name="id_users_email_adresses", type="smallint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=100, nullable=true)
*/
private $email;
/**
* @var \Users
* @ORM\Column(name="users_id")
* @ORM\OneToMany(targetEntity="Users")
*/
private $users;
,當我試圖用一個用戶顯示許多電子郵件喜歡
<td>{{ entity.name }}</td>
<td><ul>
{% for e in entity.email %}
<li>{{ e.email }}</li>
{% endfor %}
</ul></td>
顯示
即時通訊錯誤An exception has been thrown during the rendering of a template ("Notice: Undefined index: users in /var/www/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1575") in /var/www/symfony/src/Test/UserBundle/Resources/views/Users/index.html.twig at line 22
22行是for
循環
更新了我的答案 - 任何不清楚或需要更多解釋?否則請接受:) – nifr
接受:)謝謝 –
不要忘記更新您的架構與教義:架構:更新--force – nifr