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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么