Symfony - 从外部发送POST

时间:2015-06-26 00:28:34

标签: php symfony

所以我有这个控制器

/**
 * @Route("/submit", name="submit")
 */
public function submitAction(Request $request) {
    var_dump($request->getMethod());
}

现在,如果我使用

在我的树枝模板中创建表单
<form action="{{ path('submit') }}" method="post">
  <input type="text" name="text">
  <button type="submit">Submit</button>
</form>

getMethod返回POST

但是如果我做同样的事情,但在动作中使用完整的URL,就像这样

<form action="http://domain.my/submit" method="post">

getMethod会返回GET。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

非常简单

https://github.com/nelmio/NelmioCorsBundle

nelmio_cors:
    paths:
        '^/xml/':
            allow_origin: ['*']
            allow_methods: ['POST']