controller

Symfony2, check if an action is called by ajax or not

…衆ロ難τιáo~ 提交于 2020-11-28 03:38:52
问题 I need, for each action in my controller, check if these actions are called by an ajax request or not. If yes, nothing append, if no, i need to redirect to the home page. I have just find if($this->getRequest()->isXmlHttpRequest()) , but i need to add this verification on each action.. Do you know a better way ? 回答1: It's very easy! Just add $request variable to your method as use. (For each controller) <?php namespace YOUR\Bundle\Namespace use Symfony\Component\HttpFoundation\Request; class