【问题标题】:Symfony Request POSTSymfony 请求 POST
【发布时间】:2016-04-20 06:58:22
【问题描述】:

目前我正在处理 symfony 项目,但是当我尝试执行该项目时会引发一些错误。举个例子:

控制器MyAppBundle\Controller\DefaultController::updateAction() 要求您为“$request”参数提供一个值(因为 没有默认值或因为有非可选参数 在这个之后)。

我的路线:

anasayfa:
    path: /
    defaults: { _controller:MyAppBundle:Default:index}
listele:
    path: /listele
    defaults: {_controller:MyAppBundle:Default:listele}
update:
    path: /update
    defaults: {_controller:MyAppBundle:Default:update}
    requirements:
    methods: POST

还有我的控制器:

public function updateAction(Request $request){
    $em = $this->getDoctrine()->getManager();

    $username = $request->request->get('username');
    $password = $request->request->get('password');
}

最后我在主页(索引)中的表格:

<form action="{{ path('update') }}" method="POST">
    <input type="text" name="username" placeholder="Give Username">
    <input type="text" name="password" placeholder="Give Password">
    <input type="submit" value="kaydet">
</form>

我使用的是 symfony 3.0 版。

【问题讨论】:

    标签: url-routing symfony


    【解决方案1】:

    检查您的控制器文件。你用过:

    updateAction(Request $request)
    

    但是您使用的是正确的Request 对象?应该是

    use Symfony\Component\HttpFoundation\Request
    

    【讨论】:

      猜你喜欢
      • 2015-07-11
      • 2017-06-29
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 2013-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多