当我尝试创建具有特定变量类型的电影列表时,我遇到了问题。例如,所有具有流派的电影"浪漫"等等。
错误是:
ContextErrorException: Notice: Undefined index: genre in /(...)/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
Entity Genre看起来像这样:
/**
* Genre entity.
*
*/
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Genre.
*
* @package Model
* @ORM\Table(name="genre")
* @ORM\Entity(repositoryClass="AppBundle\Repository\Genre")
*/
class Genre
{
/**
* Id.
*
* @ORM\Id
* @ORM\Column(
* type="integer",
* nullable=false,
* options={
* "unsigned" = true
* }
* )
* @ORM\GeneratedValue(strategy="IDENTITY")
*
* @var integer $id
*/
private $id;
/**
* Name.
*
* @ORM\Column(
* name="name",
* type="string",
* length=128,
* nullable=false
* )
*
* @var string $name
*/
private $name;
/**
* Movies array
*
* @ORM\OneToMany(
* targetEntity="AppBundle\Entity\Movie",
* mappedBy="genre"
* )
*/
protected $movies;
/**
* Add movies.
*
* @param \AppBundle\Entity\Movie $movies Movies
*
* @return mixed
*/
public function addMovie(\AppBundle\Entity\Movie $movies)
{
$this->movies[] = $movies;
}
/**
* Remove movies
*
* @param \AppBundle\Entity\Movie $movies Movies
*
* @return mixed
*/
public function removeAnswer(\AppBundle\Entity\Movie $movies)
{
$this->movies->removeElement($movies);
}
/**
* Get movies.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getMovies()
{
return $this->movies;
}
/**
* Constructor
*/
public function __construct()
{
$this->movies = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Remove movies
*
* @param \AppBundle\Entity\Movie $movies Movies
*
* @return mixed
*/
public function removeMovie(\AppBundle\Entity\Movie $movies)
{
$this->movies->removeElement($movies);
}
/**
* Get Id.
*
* @return integer Result
*/
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
}
/**
* Set name.
*
* @param string $name Name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get name.
*
* @return string Name
*/
public function getName()
{
return $this->name;
}
}
虽然电影看起来像这样:
/**
* Movie entity.
*/
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Movie.
*
* @package Model
* @ORM\Table(name="movies")
* @ORM\Entity(repositoryClass="AppBundle\Repository\Movie")
*/
class Movie
{
/**
* Id.
*
* @ORM\Id
* @ORM\Column(
* type="integer",
* nullable=false,
* options={
* "unsigned" = true
* }
* )
* @ORM\GeneratedValue(strategy="IDENTITY")
*
* @var integer $id
*/
private $id;
/**
* Title.
*
* @ORM\Column(
* name="title",
* type="string",
* length=255,
* nullable=false
* )
*
* @var string $title
*/
private $title;
/**
* Notes.
*
* @ORM\Column(
* name="notes",
* type="text",
* nullable=true
* )
*
* @var string $notes
*/
private $notes;
/**
* Genre array
*
* @ORM\ManyToOne(targetEntity="Genre")
* @ORM\JoinColumn(name="genre_id", referencedColumnName="id")
* )
*
* @var \Doctrine\Common\Collections\ArrayCollection $genres
*/
protected $genres;
/**
* Constructor.
*/
public function __construct()
{
$this->tags = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id.
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set id.
*
* @param integer $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* Set title.
*
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Get title.
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set notes.
*
* @param string $notes
*/
public function setNotes($notes)
{
$this->notes = $notes;
}
/**
* Get notes.
*
* @return string
*/
public function getNotes()
{
return $this->notes;
}
/**
* Add genre
*
* @param \AppBundle\Entity\Genre $genres
* @return Movie
*/
public function addGenre(\AppBundle\Entity\Genre $genres)
{
$this->genres[] = $genres;
return $this;
}
/**
* Remove genre
*
* @param \AppBundle\Entity\Genre $genres
*/
public function removeGenre(\AppBundle\Entity\Genre $genres)
{
$this->generes->removeElement($generes);
}
/**
* Get genre
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getGenre()
{
return $this->genres;
}
/**
* Set genre
*
* @param \AppBundle\Entity\Genre $genres
* @return Movie
*/
public function setGenre(\AppBundle\Entity\Genre $genres = null)
{
$this->genres = $genres;
return $this;
}
在尝试这样做时,我在GenreController中使用它:
public function viewAction(Genre $genre)
{
if (!$genre) {
throw new NotFoundHttpException('Genre not found!');
}
$movies= $genre->getMovies();
return $this->templating->renderResponse(
'AppBundle:Genre:view.html.twig',
array('genre' => $genre)
);
}
现在,每当我尝试生成页面时,都会收到一条错误消息:
ContextErrorException: Notice: Undefined index: genre in /home/(...)/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1758
这是我第一次做这样的事情,所以我完全意识到它可能充满了错误,但我不知道这个来自哪里,所以对我来说真的很难做到。如果有人能告诉我我的错误,我将不胜感激。
答案 0 :(得分:1)
实体名称为流派,但您在代码的某些部分中将其引用为 Genere