我已经开发了一个控制器,用于通过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来调用此控制器的可能性。如何确定一个控制器是从开发环境还是从生产环境调用的?