簡體   English   中英

無法為命名路線“參與者”生成 URL,因為此類路線不存在

[英]Unable to generate a URL for the named route “participants” as such route does not exist

我想在我的代碼中添加這個鏈接:

<a href="{{ path('participants', {id: formation.id})  }}" class="btn btn-secondary">La liste des participants</a>

我在我的 controller 中寫了這個 function:

 /**
 * @Route("/admin/formation/{id}/participants", name="participants")
 */
public function participants(Formations $formation)
{
    $participants = $this->repositoryp->findBy(array('id_f_id' => $formation->getId() ));

    return $this->render('Formations/Participants.html.twig', [
        'participants' => $participants,
    ]);
}

但它不起作用。 我需要做什么?

在您的示例中,一切都是正確的。 可能您忘記通過注釋配置路由

檢查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)

$participants = $this->repositoryp->findBy(array('id_f_id' => $id ));

你對 go 很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM