Commandline w/ environments hack |
[eluser]jmadsen[/eluser]
CI's idea of working with the Apache env variables is nice in some ways, but has the issue of not working from the command line CIs cli syntax is also a little weird to work with, as all extra arguments get passed as variables to your function. So I threw together this rather crude but I think effective hack: Code: if ((php_sapi_name() == 'cli') or defined('STDIN')) (This of course goes in your index.php, where you define your ENVIRONMENT ) You run it normally, but then can add "--env production" at the end to set your ENVIRONMENT. Yes, simple & crude :-) Wonder if anyone has solved this in a different manner, or sees any issues with this code (not deployed at all yet, so use at own risk for now). I had considered getting fancy and rewriting the whole initialization bit with a library & pull in from vendor, but just seemed like overkill when CI is so restricted in what it accepts Jeff
[eluser]jmadsen[/eluser]
So, decided to toss together a little explanatory tut on the above code: http://codebyjeff.com/blog/2013/10/setti...ommandline Gives you a tiny dip into the Core classes, so good read if you're still relatively new to CI |
Welcome Guest, Not a member yet? Register Sign In |