Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法为命名路由生成URL;参与者“;因为这样的路线并不存在_Php_Twig_Symfony4 - Fatal编程技术网

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代码。