php Symfony2,如何改变环境?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10904960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Symfony2, How to change environment?
提问by pmoubed
I have read a lot about the clear cache command for symfony2, but I have this question :
我已经阅读了很多关于 symfony2 的清除缓存命令,但我有这个问题:
Is php app/console cache:clear --env=prodwith --env, changes the environment or just clean the cache for that environment?
是php app/console cache:clear --env=prod用--env,改变环境或只是清理缓存为环境?
If only clear the cache for that environment, then what is this line mean in app.php :
如果只清除该环境的缓存,那么 app.php 中的这一行是什么意思:
$kernel = new AppKernel('prod', false);
I think when I want to use Symfony2 Production Environment I have to change that line to
我想当我想使用 Symfony2 生产环境时,我必须将该行更改为
$kernel = new AppKernel('prod', true);
Am I in the right spot?
我在正确的位置吗?
回答by Peter Bailey
The two constructor arguments for Symfony\Component\HttpKernel\Kernelare $environmentand $debug.
Symfony\Component\HttpKernel\Kernel的两个构造函数参数是$environment和$debug。
So, to answer your question directly, app.phpalready uses the production environment. You'll notice that app_dev.phpinstantiates the kernel like this
所以,直接回答你的问题,app.php已经使用了生产环境。你会注意到app_dev.php像这样实例化内核
$kernel = new AppKernel('dev', true);
So, the environment name that you pass to the kernel constructor maps to the environment name you'd use in console commands (i.e., the --env).
因此,您传递给内核构造函数的环境名称映射到您在控制台命令中使用的环境名称(即--env)。
Does that clear it up for you?
这对你来说清楚了吗?
回答by Ahmed Siouani
To change the environment you've to change your front controller. Symfony2 provide by default three environments and a front controller for each one of them with a specific configuration files > See more
要改变环境,你必须改变你的前端控制器。Symfony2 默认提供三个环境和一个前端控制器,每个环境都有一个特定的配置文件 >查看更多
When you execute cache:clear command for a specific environment, it just clears the cache for the given environment. To change your environment, you've just to change your front controller (app.php / app_dev.php / app_test.php)
当您为特定环境执行 cache:clear 命令时,它只会清除给定环境的缓存。要改变你的环境,你只需要改变你的前端控制器(app.php / app_dev.php / app_test.php)
You can also create new environments with a specific configuration
您还可以使用特定配置创建新环境

