Php 无法为命名路由生成URL;参与者“;因为这样的路线并不存在
我想在我的代码中添加此链接:Php 无法为命名路由生成URL;参与者“;因为这样的路线并不存在,php,twig,symfony4,Php,Twig,Symfony4,我想在我的代码中添加此链接: <a href="{{ path('participants', {id: formation.id}) }}" class="btn btn-secondary">La liste des participants</a> 但它不起作用。我需要做什么?在您的示例中,一切都是正确的。可能您忘记配置您的 检查config/routes.yaml。应该有这样的配置: # config/routes.yaml controllers:
<a href="{{ path('participants', {id: formation.id}) }}" class="btn btn-secondary">La liste des participants</a>
但它不起作用。我需要做什么?在您的示例中,一切都是正确的。可能您忘记配置您的 检查
config/routes.yaml
。应该有这样的配置:
# config/routes.yaml
controllers:
resource: '../src/Controller/'
type: annotation
此配置可能位于config/routes/annotations.yaml
中
# config/routes/annotations.yaml
controllers:
resource: '../../src/Controller/'
type: annotation
如果这些文件中没有此设置,请添加它。在您的示例中,一切都是正确的。可能您忘记配置您的 检查
config/routes.yaml
。应该有这样的配置:
# config/routes.yaml
controllers:
resource: '../src/Controller/'
type: annotation
此配置可能位于config/routes/annotations.yaml
中
# config/routes/annotations.yaml
controllers:
resource: '../../src/Controller/'
type: annotation
如果这些文件中没有此设置,请添加它。您没有从请求中获取id:
/**
* @Route("/admin/formation/{id}/participants", name="participants")
*/
public function participants(Formations $formation,$id)
{
$participants = $this->repositoryp->findBy(array('id_f_id' => $id ));
return $this->render('Formations/Participants.html.twig', [
'participants' => $participants,
]);
}
转储$id,您可以获得id值,然后像以前一样进行回购调用
变化
public function participants(Formations $formation,$id)
及
你可以走了 您未能从请求中获取id:
/**
* @Route("/admin/formation/{id}/participants", name="participants")
*/
public function participants(Formations $formation,$id)
{
$participants = $this->repositoryp->findBy(array('id_f_id' => $id ));
return $this->render('Formations/Participants.html.twig', [
'participants' => $participants,
]);
}
转储$id,您可以获得id值,然后像以前一样进行回购调用
变化
public function participants(Formations $formation,$id)
及
你可以走了 对于
@Route
您还需要使用Symfony\Component\Routing\Annotation\Route
在每个具有注释的PHP文件中。使用@Route
还需要使用Symfony\Component\Routing\annotation\Route在每个包含注释的PHP文件中编写>代码。