在 symfony 7 中提交后如何更改变量

问题描述 投票:0回答:1

我在验证某些条件后单击提交按钮后尝试更改变量。 我使用普通的 html 表单而不是 symfony 表单 idk 如果有什么区别的话。 控制器:

#[Route('/test', name: 'test')]
    public function test(Request $request): Response
    {
        $response = 'a';
        if ($request->isMethod('POST')){
            $response = "value changed";
        }
        return $this->render('charge/test.html.twig', [
            'response' => $response
        ]);
    }

模板:

{% extends 'base.html.twig' %}

{% block title %}Hello !{% endblock %}

{% block body %}
    <div class="container">
        <h1>{{ response }}</h1>
        <form method="post">
            <input type="submit" name="sub1" value="sub1">
            <input type="submit" name="sub2" value="sub2">
        </form>
    </div>
{% endblock %}

单击任何提交按钮后,响应值永远不会改变。

symfony twig
1个回答
0
投票

我想找到了解决方案
我所要做的就是对我的项目执行这个命令:

composer require nelmio/cors-bundle
© www.soinside.com 2019 - 2024. All rights reserved.