路由中的转发变量
Forward variable in route
我正在尝试为树枝模板中的路由转发一个变量。但是我的方法不行。
用户可以创建一个有多个人物的项目,人物的路线是admin/projet/{idProjet}/personnages/{idPersonnage}
所以当我在人物表演中我需要恢复idProjet
我尝试传入渲染但也不起作用
我的项目控制器
/**
* @Route("admin/projet/{id}", name="projet_show", methods={"GET"})
*/
public function show(Projet $projet, Request $request): Response
{
$chapitres = $this->getDoctrine()
->getRepository(Chapitre::class)
->findByProjet($projet->getId());
$personnages = $this->getDoctrine()
->getRepository(Personnages::class)
->findByProjet($projet->getId());
$idProjet = $projet->getId();
return $this->render('projet/show.html.twig', [
'projet' => $projet,
'idProjet' => $idProjet,
'chapitres' => $chapitres,
'personnages' => $personnages
]);
}
树枝中的项目展示
{% for personnage in personnages %}
<div class="list-group">
<a href="{{ path('personnages_show', {'idPersonnage':
personnage.id},
{ 'idProjet': idProjet}) }}" class="list-group-item list-group-
item-action">
{% if personnage.role == 'Héros' %}
<i class="fas fa-chess-queen"></i> {{ personnage.firstName }} {{
personnage.lastName }}
{% elseif personnage.role == 'Secondaire'%}
<i class="fas fa-chess-knight"></i>
{{ personnage.firstName }} {{ personnage.lastName }}
{% else %}
错误信息:
An exception has been thrown during the rendering of a template (Some mandatory parameters are missing (`idProjet`) to generate a URL for route `personnages_show`.).
path
的参数格式不正确。
href="{{ path('personnages_show', {'idPersonnage': personnage.id, 'idProjet': idProjet}) }}"
通过使用额外的括号,idProject
被作为 absolute
选项传递。
我正在尝试为树枝模板中的路由转发一个变量。但是我的方法不行。
用户可以创建一个有多个人物的项目,人物的路线是admin/projet/{idProjet}/personnages/{idPersonnage}
所以当我在人物表演中我需要恢复idProjet
我尝试传入渲染但也不起作用
我的项目控制器
/**
* @Route("admin/projet/{id}", name="projet_show", methods={"GET"})
*/
public function show(Projet $projet, Request $request): Response
{
$chapitres = $this->getDoctrine()
->getRepository(Chapitre::class)
->findByProjet($projet->getId());
$personnages = $this->getDoctrine()
->getRepository(Personnages::class)
->findByProjet($projet->getId());
$idProjet = $projet->getId();
return $this->render('projet/show.html.twig', [
'projet' => $projet,
'idProjet' => $idProjet,
'chapitres' => $chapitres,
'personnages' => $personnages
]);
}
树枝中的项目展示
{% for personnage in personnages %}
<div class="list-group">
<a href="{{ path('personnages_show', {'idPersonnage':
personnage.id},
{ 'idProjet': idProjet}) }}" class="list-group-item list-group-
item-action">
{% if personnage.role == 'Héros' %}
<i class="fas fa-chess-queen"></i> {{ personnage.firstName }} {{
personnage.lastName }}
{% elseif personnage.role == 'Secondaire'%}
<i class="fas fa-chess-knight"></i>
{{ personnage.firstName }} {{ personnage.lastName }}
{% else %}
错误信息:
An exception has been thrown during the rendering of a template (Some mandatory parameters are missing (`idProjet`) to generate a URL for route `personnages_show`.).
path
的参数格式不正确。
href="{{ path('personnages_show', {'idPersonnage': personnage.id, 'idProjet': idProjet}) }}"
通过使用额外的括号,idProject
被作为 absolute
选项传递。