收到的Symfony无POST数据 [英] No POST data received Symfony

查看:888
本文介绍了收到的Symfony无POST数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题苦苦挣扎,因为我在生产mutualized服务器上。 我有一个防火墙保护我的管理面板/管理/*.

在此管理面板,所有我发送POST数据没有到达控制器。

 的var_dump($这个 - >获得(请求) - >请求 - >所有的())
 

给我一个空数组 ,同样的事情:

 的var_dump($ _ POST)
 

这是很烦人的,因为我所有的形式和CRUD功能不工作了... 其他网页我的网站(而不是在管理面板)的不正常工作。

在Chrome和Firebug的控制台告诉我,该数据被送到正确的方式。

我在想一个问题,我的.htaccess文件:

 < IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^(。*)$网​​/ $ 1 [QSA,L]
< / IfModule>
 

我有我的www目录此文件指向的网页目录

 的RewriteCond%{THE_REQUEST} ^(GET | HEAD)\ /网络/
重写规则^(。*)/ $ 1 [L,R = 301]
 

和我在我的web目录的.htaccess中加入该

我的防火墙:

 防火墙:
    secured_area:
        模式:^ /
        匿名:〜
        form_login:
            login_path:/登录
            check_path:/ login_check
            always_use_default_target_path:真
            default_target_path:/管理
            use_referer:真
        登出:
            路径:/注销
            目标:/登录

访问控制:
     -  {路径:^ /管理,角色:ROLE_ADMIN}
 

控制器功能的我的PHP code:

 公共职能testAction(){
    返回新的响应(后续代码var_dump($ _ POST));
}
 

简单的HTML表单:

 <形式的行动={{path_for_controller}}方法=POST/>
<输入类型=文本名称=搜索/>
<输入类型=提交值=送/>
< /形式GT;
 

只需$这个 - >获得(请求) - >获得(搜索)给了我零和POST也是空的

感谢你的帮助,我真的越来越绝望......

修改

我注意到它清除我的缓存,但只一会儿

后曾几次
解决方案

我碰到这个问题,前段时间来了。但我的问题是重定向(重写)。的形式提交到正确的网址,但重写被重定向到另一个位置,并重定向不要随身携带后的数据。

在Chrome浏览器开发者控制台,如果你检查 preserve日志,那么你就可以看出来。

我觉得你的情况,这是造成问题

 的RewriteCond%{THE_REQUEST} ^(GET | HEAD)\ /网络/
重写规则^(。*)/ $ 1 [L,R = 301]
 

最好的事情设置Symfony2的,我想说的是,设置你的的DocumentRoot 网​​站目录,比做它通过的.htaccess

I am struggling with a strange problem since I'm on production on a mutualized server. I have a firewall securing my admin panel matching all the url with /admin/*.

On this administration panel, all the POST data that I send do not arrive to the controller.

var_dump($this->get('request')->request->all())

gives me an empty array , same thing for :

var_dump($_POST)

This is very annoying since all my forms and CRUD functionalities do not work anymore... The other pages of my website (not on the admin panel) do work correctly.

The Chrome and FireBug console show me that the data is sent the right way.

I'm thinking of a problem with my .htaccess files :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>

I have this file on my www directory to point to the web directory

RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /web/
RewriteRule ^(.*)$ /$1 [L,R=301]

And I've added this in the .htaccess of my web directory

My firewalls :

    firewalls:
    secured_area:
        pattern:   ^/
        anonymous: ~
        form_login:
            login_path:  /login
            check_path:  /login_check
            always_use_default_target_path: true
            default_target_path:            /admin
            use_referer:                    true
        logout:
            path:   /logout
            target: /login

access_control:
    - { path: ^/admin, roles: ROLE_ADMIN }

My PHP code of the controller function :

public function testAction() {
    return new Response(var_dump($_POST));
}

Simple HTML form :

<form action="{{path_for_controller}}" method="POST"/>
<input type="text" name="search"/>
<input type="submit" value="send"/>
</form>

Just $this->get('request')->get('search') gives me null and POST is also empty.

Thank you for your help, I'm really getting desperate ...

EDIT

I noticed that it worked a few times after clearing my cache but only for a moment

解决方案

I came across this issue some time ago. But my problem was redirection(rewrite). The form was being submitted to right URL but the rewrite was redirecting it to another location, and redirection dont carry along post data.

In chrome developer console, if you check Preserve log, then you will be able to see it.

I think in your case this is causing problems

RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /web/
RewriteRule ^(.*)$ /$1 [L,R=301]

Best thing to setup Symfony2, I would say is , set your DocumentRoot to the web directory, than doing it through .htaccess

这篇关于收到的Symfony无POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆