8
I've developed a controller for answering to AJAX petitions using JSON:
class PeopleController extends Controller
{
public function listAction()
{
$request = $this->getRequest();
// if ajax only is going to be used uncomment next lines
//if (!$request->isXmlHttpRequest())
//throw $this->createNotFoundException('The page is not found');
$repository = $this->getDoctrine()->getRepository('PeopleManagerBundle:People');
$items = $repository->findAll();
// yes, here we are retrieving "_format" from routing. In our case it's json
$format = $request->getRequestFormat();
return $this->render('::base.'.$format.'.twig', array('data' => $items));
}
I've enabled the HTML view, as it is very useful for debugging, but I'd like to limit the possibility of calling this controller with _format=html while the app is in production. How can I determine if a controller is called from a development environment or from a production environment?