Check if in quot;devquot; mode inside a Controller with Symfony(检查是否在“开发中带有 Symfony 的控制器内的模式)
问题描述
在 Symfony2.x 应用程序中使用开发模式时,通常在语言环境中工作.因此,此类功能无法按预期工作(例如,尝试获取 localhost 下的当前 IP).这可能是一个问题,例如当尝试使用这种基于 IP 的 Web 服务时.因此,我只想知道如何在控制器内部检查 Symfony2 应用程序是否在 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.
有什么想法吗?
推荐答案
要在 Controller
中获取当前环境,您可以使用:
To get the current environment in a Controller
you can use:
$this->container->getParameter('kernel.environment');
所以你只需将它放在 if()
语句中以检查它是否等于 dev
.
So you just put that in an if()
statement to check if it equals to dev
.
这篇关于检查是否在“开发"中带有 Symfony 的控制器内的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检查是否在“开发"中带有 Symfony 的控制器内的模式


- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Laravel 仓库 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01