8
我已经开发了一个控制器使用JSON回答到AJAX请愿书呼吁:Symfony2的:决定一个控制器从开发环境或生产环境
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调用此控制器的可能性。如何确定控制器是从开发环境还是从生产环境调用?
http://stackoverflow.com/questions/8272090/get-environment-inside-controller – moonwave99