1
Im有點問題。 我有2類: Carorder:Symfony&Doctrine:嘗試訪問一對多時未定義的索引
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Entity\Orderdetail;
/**
* @ORM\Entity
* @ORM\Table(name="carorder")
*/
class Carorder
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="Orderdetail", mappedBy="Carorder", cascade={"persist","remove"})
**/
protected $orderdetails;
//Then all the auto genereted setters and getters beneath here
的OrderDetail:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/** @ORM\Entity
* @ORM\Table(name="orderdetail")
*/
class Orderdetail
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Carorder", inversedBy="orderdetails")
**/
protected $carorder;
/**
* @ORM\Column(type="integer")
*/
protected $amount;
//Then all the auto generated setters and getters beneath here
我無法通過Carorder訪問的OrderDetail。比如這個例子,只是thorws的
Undefined index: Carorder
例子:
$repository = $this->getDoctrine()->getRepository('AppBundle:Carorder');
$orders = $repository->findAll();
$orderdetail = $orders[0]->getOrderdetails()->first();
我不知道是什麼原因造成這一點,所以我希望你們能幫助我。
誤差精確定位到該示例中的第一行,你提供的? –