Check if in quot;devquot; mode inside a Controller with Symfony(检查是否在“开发中带 Symfony 的控制器内的模式)
问题描述
在 Symfony2.x 应用程序中使用开发模式时,通常在语言环境中工作.因此,此类功能无法按预期工作(例如,尝试获取 localhost 下的当前 IP).这可能是一个问题,例如当您尝试使用这种基于 ip 的网络服务时.因此,我只想知道如何在控制器内部检查 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 的控制器内的模式


- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01