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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With