drjmrg8766 2018-03-25 03:53
浏览 33
已采纳

Symfony:如何传递动态userId表单列表页面以编辑更新数据页面在CURD Opteration中

I am new developer for symfony. How to pass dynamic userId form list page to edit page?. Any one explain to me.

  • 写回答

1条回答 默认 最新

  • donglu8549 2018-03-25 17:43
    关注

    You can pass it as a parameter like this:

    In the twig template, use

    <a href="{{ path('name_of_edit_action', {'id' : user.id}) }}">edit user</a>

    This is the link that leads to the edit page. Assuming you user object has been passed to the template as 'user'. Ofcourse 'name_of_edit_action' can be anything, as long as it matches the name of the action in the edit controller.

    Then in the edit controller, you can catch the user id like this: (hypothetical route, doesn't matter, the point is the {id} part.)

    /**
    * @Route("user/edit/{id}", name="name_of_edit_action")
    */
    public function edit(User $user)
    {
    
    //at this point you have the user object at your disposal and you can pass it to the template as usual
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?