duanpin9531 2015-12-14 13:57
浏览 41

Doctrine表单生成抛出Twig错误

I have a class that have relationships with other classes in my Bundle, and whenever I try to generate a form with the Doctrine command in Symfony, it fails by returning a Twig error

Key "school" for array with keys "id, startDate, endDate" does not exists in "form/formType.php.twig" at line 29 Here is my code:

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Classroom
*
* @ORM\Table(name="classroom")
* @ORM\Entity(repositoryClass="AppBundle\Repository\ClassroomRepository")
*/
class Classroom
{
/**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @ORM\ManyToOne(targetEntity="AppBundle\Entity\School", inversedBy="classrooms")
 * @ORM\JoinColumn(nullable=false)
 */
private $school;

/**
 * @ORM\OneToMany(targetEntity="AppBundle\Entity\Student", mappedBy="classroom")
 * @ORM\JoinColumn(nullable=false)
 */
private $students;

/**
 * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Teacher")
 * @ORM\JoinColumn(nullable=false)
 */
private $teachers;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="start_date", type="date")
 */
private $startDate;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="end_date", type="date")
 */
private $endDate;

/**
 * Get id
 *
 * @return int
 */
public function getId()
{
    return $this->id;
}

/**
 * Set startDate
 *
 * @param \DateTime $startDate
 *
 * @return Classroom
 */
public function setStartDate($startDate)
{
    $this->startDate = $startDate;

    return $this;
}

/**
 * Get startDate
 *
 * @return \DateTime
 */
public function getStartDate()
{
    return $this->startDate;
}

/**
 * Set endDate
 *
 * @param \DateTime $endDate
 *
 * @return Classroom
 */
public function setEndDate($endDate)
{
    $this->endDate = $endDate;

    return $this;
}

/**
 * Get endDate
 *
 * @return \DateTime
 */
public function getEndDate()
{
    return $this->endDate;
}

/**
 * Set school
 *
 * @param \AppBundle\Entity\School $school
 *
 * @return Classroom
 */
public function setSchool(\AppBundle\Entity\School $school)
{
    $this->school = $school;

    return $this;
}

/**
 * Get school
 *
 * @return \AppBundle\Entity\School
 */
public function getSchool()
{
    return $this->school;
}
/**
 * Constructor
 */
public function __construct()
{
    $this->students = new \Doctrine\Common\Collections\ArrayCollection();
}

/**
 * Add student
 *
 * @param \AppBundle\Entity\Student $student
 *
 * @return Classroom
 */
public function addStudent(\AppBundle\Entity\Student $student)
{
    $this->students[] = $student;

    return $this;
}

/**
 * Remove student
 *
 * @param \AppBundle\Entity\Student $student
 */
public function removeStudent(\AppBundle\Entity\Student $student)
{
    $this->students->removeElement($student);
}

/**
 * Get students
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getStudents()
{
    return $this->students;
}

/**
 * Add teacher
 *
 * @param \AppBundle\Entity\Teacher $teacher
 *
 * @return Classroom
 */
public function addTeacher(\AppBundle\Entity\Teacher $teacher)
{
    $this->teachers[] = $teacher;

    return $this;
}

/**
 * Remove teacher
 *
 * @param \AppBundle\Entity\Teacher $teacher
 */
public function removeTeacher(\AppBundle\Entity\Teacher $teacher)
{
    $this->teachers->removeElement($teacher);
}

/**
 * Get teachers
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getTeachers()
{
    return $this->teachers;
}
}

Do I need to add anything for it to works ? Is it because of the relationships with another class ? Hope you can help me

  • 写回答

1条回答 默认 最新

  • duanji1043 2015-12-14 16:18
    关注

    As you didn't mention your Symfony version, it seems to me that you are having the same error as here:

    Generating forms with Symfony 2.8 throws a Twig_Error_Runtime

    Please check the solutions there

    (Sorry for putting this in an answer, I don't have the reputation to comment in your question)

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀