Hopefully a simple question - how does one specify which environment to use when running a console command in Symfony2. I've created a few commands, however I would like to run them in the context of my 'staging' environment when on my staging server and my 'prod' environment when on my production server (the different environments define different database connections). How do I configure and pass this information to my console command?
Selecting the Active Environment Symfony applications come with a file called . env located at the project root directory.
The Symfony framework provides lots of commands through the bin/console script (e.g. the well-known bin/console cache:clear command). These commands are created with the Console component. You can also use it to create your own commands.
The Console component eases the creation of beautiful and testable command line interfaces. The Console component allows you to create command-line commands. Your console commands can be used for any recurring task, such as cronjobs, imports, or other batch jobs.
If you have file system access to the project Look inside the file for a line like: const VERSION = '5.0. 4'; that's the Symfony version number.
You have two options that will help you out. You can specify the environment that the console will run in with the --env
flag, and use --no-debug
to disable debug mode.
php app/console --env=staging your:console:command
or php app/console --env=prod your:console:command
should do what you're looking for (the console runs in the dev
environment with debug on by default).
You can look at the code of the app/console
file for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With