我开发了一个控制器,用于使用 JSON 响应 AJAX 请愿:
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));
}
我已启用 HTML 视图,因为它对调试非常有用,但我想限制在应用程序处于生产状态时使用 _format=html 调用此控制器的可能性。如何确定控制器是从开发环境调用还是从生产环境调用?