Doctrine表单生成抛出Twig错误

时间:2015-12-14 13:57:22

标签: php symfony doctrine symfony-forms

我有一个类与我的Bundle中的其他类有关系,每当我尝试在Symfony中使用Doctrine命令生成表单时,它会因返回Twig错误而失败

Key" school"对于带有键的数组" id,startDate,endDate"在" form / formType.php.twig"中不存在在第29行 这是我的代码:

<?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;
}
}

我需要添加任何内容吗?是因为与另一个班级的关系? 希望你能帮帮我

1 个答案:

答案 0 :(得分:1)

由于您没有提及您的Symfony版本,在我看来您遇到的错误与此处相同:

Generating forms with Symfony 2.8 throws a Twig_Error_Runtime

请检查那里的解决方案

(很抱歉把这个放回答案中,我没有在你的问题中发表评论的声誉)