douwo8140 2017-06-09 11:13
浏览 30
已采纳

使用symfony3预期值进行注释错误,得到“POST”

I have Symfony app and I try to submit a simple form to action function which..and obviously my annotations are wrong but I don't know how to fix them. Here is the full error

[Syntax Error] Expected Value, got 'POST' at position 58 in method AppBundle\Controller\ProjectController::showAction() in C:\xampp\htdocs\TaskManager\src\AppBundle/Controller/ (which is being imported from "C:\xampp\htdocs\TaskManager\app/configouting.yml").

Here is the form I am trying to submit in show.html.twig

<form method="post">
    <input type="submit" name="approve" value="Approve">
    <input type="submit" name="reject" value="Reject">
</form>

The reason behind it is that I have a single type of user which can Approve or Reject a project. This user should not go to edit page just to change those two fields. Instead it should click two buttons and the values should change without him doing anything else. My idea is to have this code in the showAction() -

if (isset($_POST['approve'])) {
    $project->setApproved(true);
    $project->setRejected(false);
}
elseif (isset($_POST['rejected'])) {
    $project->setRejected(true);
    $project->setApproved(false);
}

After I change those values I intend on flushing them so when the project is shown again it will be either Approved or Rejected. The key here is that there should be no fields. When I want to show a project I already have everything needed to flush it. Here are my annotations for the showAction() -

/**
 * Finds and displays a project entity.
 *
 * @Route("/{id}", name="project_show")
 * @Method("GET","POST")
 */

Just for comparison here are my annotations in editAction() which works fine

/**
 * Displays a form to edit an existing project entity.
 *
 * @Route("/{id}/edit", name="project_edit")
 * @Method({"GET", "POST"})
 */

What do I need to be able to submit this one simple form in my showAction()?

  • 写回答

1条回答 默认 最新

  • dongposhi8677 2017-06-09 11:20
    关注

    Looks like you're missing brace ({}) in @Method annotation

    Try to change this:

    * @Method("GET","POST")
    

    To this:

    * @Method({"GET","POST"})
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助