-2
当试图输出与任务关联的所有附件(附件实体)时,我会得到以下异常。但我不知道为什么。未定义指数:symfony2从OneToMany实体输出数据TWIG
一个例外模板(简称“通知的渲染过程中被抛出任务/应用程序/ MAMP/htdocs中/ Seotool /供应商/教义/ ORM/lib中/教义/ ORM /持久化/ BasicEntityPersister在/Applications/MAMP/htdocs/Seotool/src/Seotool/MainBundle/Resources/views/Task/load_task.html.twig .PHP线1753" )在管线10
TWIG:
{{ tasks.taskDescription }}
{% for attachment in tasks.Attachments %}
{{ attachment.id }}
{% endfor %}
控制器:
/**
@Route(
* path = "/tasks/load/{id}",
* name = "load_task"
*)
* @Template()
*/
public function load_taskAction($id, Request $request)
{
$tasks = $this->getDoctrine()
->getRepository('SeotoolMainBundle:Task')
->find($id);
return array(
'tasks' => $tasks
);
}
任务实体:
/**
* @ORM\OneToMany(targetEntity="Attachments", mappedBy="task",cascade={"persist"})
*/
protected $attachments;
附件实体:
/**
* @ORM\ManyToOne(targetEntity="Task", inversedBy="attachments")
* @ORM\JoinColumn(name="task", referencedColumnName="id")
*/
protected $Task;
更改保护$任务;保护$任务; 您可能会收到另一条错误: {%为附件在任务中。附件%}将其更改为 {%for attachment in tasks.attachments%} – mohsenJsh 2014-08-30 16:55:03
谢谢,现在可以使用:) – Marvin 2014-08-30 18:02:21
欢迎您:) 。在更改$ Task之前,它是否正常工作?在您的addAttachment()方法中放入$ attachment-> addTask($ this); *** ; – mohsenJsh 2014-08-30 19:19:13