简体   繁体   English

Symfony2,如何改变环境?

[英]Symfony2, How to change environment?

I have read a lot about the clear cache command for symfony2, but I have this question : 我已经阅读了很多关于symfony2的clear cache命令,但我有这个问题:

Is php app/console cache:clear --env=prod with --env , changes the environment or just clean the cache for that environment? php app/console cache:clear --env=prod with --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? 我在正确的位置吗?

The two constructor arguments for Symfony\\Component\\HttpKernel\\Kernel are $environment and $debug . Symfony \\ Component \\ HttpKernel \\ Kernel的两个构造函数参数是$environment$debug

So, to answer your question directly, app.php already uses the production environment. 因此,为了直接回答您的问题, app.php已经使用了生产环境。 You'll notice that app_dev.php instantiates the kernel like this 您会注意到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 (ie, the --env ). 因此,传递给内核构造函数的环境名称映射到您在控制台命令中使用的环境名称(即--env )。

Does that clear it up for you? 那清楚了吗?

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. 当您为特定环境执行cache:clear命令时,它只会清除给定环境的缓存。 To change your environment, you've just to change your front controller (app.php / app_dev.php / app_test.php) 要改变你的环境,你只需更改你的前端控制器(app.php / app_dev.php / app_test.php)

You can also create new environments with a specific configuration 您还可以使用特定配置创建新环境

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM