2016-06-23 20 views
1

私は、特定の変数Genreを持つムービーのリストを作成しようとしているときに問題に遭遇しています。たとえば、ジャンルが「ロマンス」のすべての映画などです。Symfony2:ContextErrorException

エラーは次のとおりです。

ContextErrorException: Notice: Undefined index: genre in /(...)/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php 

エンティティジャンルは次のようになります。

/** 
* 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; 
} 

そして、これをやろうとしている間、私が使用:映画はこのように見えますが

/** 
* 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; 
} 
} 

これはGenControllerの

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 

それは私がこのような何かをやっている最初の時間ですので、私はそれがエラーのおそらくフルの完全承知していますしかし、私はこれがどこから来ているのか分からないので、私はそれについて何かをするのは本当に難しいです。誰かが私に間違いを見せてくれたら、私は感謝します。

答えて

1

エンティティ名はジャンルですが、コード

+0

のいくつかの部分にGenereとしてそれを参照し、これが主な問題ではありませんが、はい、それは、正しいです。私のファイルでは、それは技術的にはスペルミスであることがわかっていても、私はちょうど "genere"を持っていますが、私は後でそれに取り掛かりたいと思います。 – Nunuz

+0

次に、Moviesクラスの$ generes変数になります。ジェネレアクラスの$ moviesの関係では、あなたが書きました:variablaの名前は複数ですが、mappedBy = "genre"は単数です – izambl

+0

いいえ、そうではありません。私が言ったように、私のファイルでは、名前は常に "genere"です。ここで私はそれを変更したかったので、何らかの理由で見た目が良くなり、一部の遺伝子が変更され、残りは同じままになりました。とにかく、それは私のファイルでは正しいので、これは問題の根源ではありません。 – Nunuz