Reputation: 10583
I have two different controllers in a Symfony2 app.
One controller returns the correct User object and one returns NULL (or anonymous user) when calling
$this->getUser();
They're exactly the same. Neither is doing anything special before the call to $this->getUser()
, other than the anon one is being called by Ajax. My other Ajax calls are fine, but this one is not finding the logged in user when called via Ajax.
Upvotes: 1
Views: 479
Reputation: 23311
Make Sure Your Domains and URLs Match Up Perfectly
The two action URLs are slightly different and therefore are being called in a slightly different way meaning the session cookies do not work correctly.
Make sure that you are calling the same host. I.e. if you have "dev1.test.com" and "dev2.test.com" hosts setup and your AJAX is a calling a different one to your controller.
Secondly, make sure your endpoint is the same. If you call "dev.test.com:8888/app_dev.php/api" on the controller and "dev.test.com:8888/api" for the AJAX it will not work either.
Hope this helps.
Upvotes: 1