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