我有many-to-many
关系。实体是Actor
和Pys
(电影和电视节目)。当我想要电影演员时,关系工作正常(返回电影的所有演员和女演员)但是当我想检索演员的所有电影时问题就来了。
这是 phpmyadmin 中的关系:
这是出现的错误:
Key "actor" for array with keys "0" does not exist in ActorBundle:Default:actor.html.twig at line 3
这里是必要的代码:
演员的DefaultController
class DefaultController extends Controller
{
public function peliculasAction($actId)
{
$em = $this->getDoctrine()->getManager();
$peliculas = $em->getRepository('ActorBundle:Actor')->findPeliculas($actId);
return $this->render('ActorBundle:Default:actor.html.twig', array('peliculas' => $peliculas
));
}
}
ActorRepository
class ActorRepository extends EntityRepository
{
public function findPeliculas($actId)
{
$em = $this->getEntityManager();
$consulta = $em->createQuery('
SELECT p, d, a
FROM ActorBundle:Actor a
JOIN a.pys p JOIN p.director d
WHERE a.actId = :actId
ORDER BY p.pysAnyo DESC
');
$consulta->setParameter('actId', $actId);
return $consulta->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker')->getResult();
}
}
actor.html.twig
(...)
{% block title %}{{ peliculas.actor.actNombre ~ ' ' ~ peliculas.actor.actApellidos }}{% endblock %}
{% block article %}
<section class="article">
<div id="datos-actor-director-genero">
<strong>{{ 'Nombre:' | trans }} </strong>{{ peliculas.actor.actNombre ~ ' ' ~ peliculas.actor.actApellidos }}</br>
<strong>{{ 'Fecha de nacimiento:' | trans }} </strong>{{ peliculas.actor.actFechaNacimiento | localizeddate('long', 'none') }}
</div>
<table>
{% for pys in peliculas %}
<tr id="fechaVotacion">
<td colspan="4">{{ pys.pysAnyo }}</td>
(...)