ho sviluppato un controller per rispondere alle petizioni AJAX utilizzando JSON:Symfony2: determinare se un controller è chiamato da un ambiente di sviluppo o da un ambiente di produzione
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));
}
ho attivato la visualizzazione HTML, come è molto utile per il debug, ma mi piacerebbe limitare la possibilità di chiamare questo controller con _format = html mentre l'app è in produzione. Come posso determinare se un controller viene chiamato da un ambiente di sviluppo o da un ambiente di produzione?
http://stackoverflow.com/questions/8272090/get-environment-inside-controller – moonwave99