检查是否在“dev”模式内的一个控制器与Symfony2.x [英] Check if in "dev" mode inside a Controller with Symfony2.x

查看:302
本文介绍了检查是否在“dev”模式内的一个控制器与Symfony2.x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用带有 Symfony2.x 应用程序的开发模式时,通常在区域设置中使用。因此,这样的功能不能按预期工作(例如,尝试获取localhost下的当前IP)。这可能是一个问题,例如。当一个尝试使用这样的基于ip的web服务时。因此,我只想知道如果Symfony2应用程序在 dev 模式下运行,如何检查控制器内部。



任何想法?

  $ this-> container-> getParameter('kernel.environment'); 

所以你只需把它放在 if()语句检查它是否等于 dev


When using dev mode with a Symfony2.x application, one usually works in locale. Hence, such function does not works as expected (for instance, try to get the current IP under localhost). This could be a problem, e.g. when one try to use such ip-based web service. Hence, I just want to know how to check inside a controller if the Symfony2 application is running in dev mode or not. In that way one can set the behavior of the controller depending by the mode.

Any idea?

解决方案

To get the current environment in a Controller you can use:

$this->container->getParameter('kernel.environment');

So you just put that in an if() statement to check if it equals to dev.

这篇关于检查是否在“dev”模式内的一个控制器与Symfony2.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆