我有一个页面address.html.twig,用户可以在表UserAddress中添加许多地址。当他在数据库中添加他的地址时,应该在他添加地址的同一页面中呈现地址,然后他可以选择他想使用的地址。不幸的是地址不是渲染。学说和Symfony2:协会是指不存在的反面错误
首先,我以为我的控制器操作或我的树枝页面有问题。我甚至在这里问了一个问题吧=>here
我验证了我的所有表中的phpmyadmin和所有的人都是很好的链接,但如果我这样做:PHP应用程序/控制台学说:架构:验证 我有这个错误:
[映射] FAIL - 实体级 'FLY \ BookingsBundle \实体\ Commandes' 映射无效: *的关联FLY \ BookingsBundle \实体\ Commandes#用户指逆侧场 Application \ Sonata \ UserBundle \ Entity \ User#commandes其中不存在 存在。
[映射] FAIL - 实体级 'FLY \ BookingsBundle \实体\ UserAddress' 映射无效: *的关联FLY \ BookingsBundle \实体\ UserAddress#用户指逆侧场 应用\奏\ UserBundle \ Entity \ User#地址不存在 。
看一看这样的画面:
这是我UserAddress.php
/**
* @ORM\ManyToOne(targetEntity="Application\Sonata\UserBundle\Entity\User", inversedBy="address")
* @ORM\JoinColumn(nullable=true)
*/
private $user;
Commandes.php
/**
* @ORM\ManyToOne(targetEntity="Application\Sonata\UserBundle\Entity\User", inversedBy="commandes")
* @ORM\JoinColumn(nullable=true)
*/
private $user;
user.php的
/**
* @ORM\Entity(repositoryClass="FLY\UserBundle\Repository\UserRepository")
* @ORM\Table(name="fos_user_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
$this->commandes = new \Doctrine\Common\Collections\ArrayCollection();
$this->address = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @ORM\OneToMany(targetEntity="FLY\BookingsBundle\Entity\Commandes", mappedBy="user", cascade={"remove"})
* @ORM\JoinColumn(nullable=true)
*/
private $commandes;
/**
* @ORM\OneToMany(targetEntity="FLY\BookingsBundle\Entity\UserAddress", mappedBy="user", cascade={"remove"})
* @ORM\JoinColumn(nullable=true)
*/
private $address;
在这里你可以看到我的VAR转储:
User {#124 ▼
#id: 21
-commandes: null
-address: null
}
这可能是一个命名空间错误。用户如何拥有@ORM \ Entity(repositoryClass =“FLY \ UserBundle \ Repository \ UserRepository”)的存储库类,但根据Commandes,用户实体位于Application \ Sonata \ UserBundle \ Entity \ User中 - 在单独的包中生成。彻底检查你的映射是否指向你实体的正确命名空间。 – Richard