Symfony 1.4:以编程方式设置 CLI 环境
我有一个基于 Symfony 1.4 构建的项目,它有多个环境 - 每个开发人员都在其本地计算机上安装了自己的副本,因此有自己的环境。
我可以在 index.php 中动态设置环境,但是如何为 CLI 任务执行此操作?
我当然可以在所有任务上使用 --env=myenvironment,但我希望它能够使用与我在 index.php 中相同的逻辑
I have a project built on Symfony 1.4 and it has multiple environments - each developer has their own copy installed on their local machine and therefore has their own environment.
I am able to dynamically set the environment in index.php, but how can I do this for CLI tasks?
I could of course use --env=myenvironment on all tasks, but I would prefer it to be able to use the same logic as I have in index.php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
sfContext::getInstance()->getConfiguration()->getEnvironment()
sfContext::getInstance()->getConfiguration()->getEnvironment()
你可以在你的任务中做类似的事情:
上面应该有效;如果environment.cfg 文件不存在,则默认为“prod”环境。这还假设您在文件中只有环境(例如“prod”、“dev”、“slappythefish”等)。
You could do something similar to this in your task perhaps:
The above should work; it defaults to the 'prod' environment if the environment.cfg file doesn't exist. This also assumes that you have just the environment in the file (eg 'prod', 'dev', 'slappythefish' etc).