【问题标题】:How do I add a parameter ton my path symfon4?如何向我的路径 symfony 4 添加参数?
【发布时间】:2020-05-04 02:00:02
【问题描述】:

您好,我试图为我的路径提供一个 id 参数,但是当我单击按钮以使用 id 转到我的 url 时出现错误,并且 url 显示 /x 而不是 Id。

我已经试过了

<a href="{{ path('confirm_selected_cours', {'id': cour.id }) }}" class="btn btn-primary float-right" role="button">S'inscrire dans ce cours</a>

但是没有用

这是我的代码

<ul class="list-group">
 {% for cour in cours %}
     <li class="list-group-item list-group-item-warning">
         {{ cour.title }}
         <a href="{{ path('confirm_selected_cours', {'id': cour.id }) }}" class="btn btn-primary float-right" role="button">S'inscrire dans ce cours</a>
    </li>
 {% endfor %}

这是在我的控制器中 `/** * @Route("/etudiant/inscription-cours/{id}", name="confirm_selected_cours") */

public function confirmRegistrationCours($id)
{
     $repoCours = $this->getDoctrine()->getRepository(Cours::class);
     $cours = $repoCours->find($id);
     return $this->render('student/show_selected_cours.html.twig', [
         'cour' => $cours
     ]);

}`

【问题讨论】:

  • 我忘了说,当我输入带有 myslef id 的 url 时,页面会显示所有信息

标签: php doctrine-orm twig symfony4


【解决方案1】:

我使用的是 id 而不是 ID,所以我添加了这个,因为我必须使用 30 个字符来发布

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    相关资源
    最近更新 更多