We do it differently, and better in my opinion. In your bootstrap:
1) Figure out which type of env
2) Load appropriate config
3) Set the config object in the registry
In your controller super class be sure to set a protected member
$_config, which you can get from the registry during construction.
Now $this->_config is always available in your controllers. You can do
the same for your model super class too.
We do stuff with ini files and sections, we also merge several configs
because the app is layered in a specific way for our stuff, and we even
allow loading custom configs so developers can setup whatever type of
config they want on their own local machines, but that's the basics.
BTW, we used to use SetEnv in apache but quickly figured out that it
doesn't help you when you're doing cli php. We run cronjobs written in
php for lots of different stuff and crons need a dev env too. So, we
figured out we could actually use php.ini to set the env, which will
allow us to know the env using php as an apache module OR cli. First set
a directive in your php.ini, like:
app_environment = "dev"
Then in your bootstrap you can access this with:
get_cfg_var('app_environment')
- Tony
On 12/2/2007 11:33 AM, robert mena wrote:
Hi,
I've adopted ZF as the framework that I am rewriting my modules. One
of the things I'd like to do is have a better way of changing /
defining some of my modules' behaviour.
I am considering using Zend_Config (not sure if .ini o .xml) and have
development, stagging and production config files. When the bootstrap
is called I find out which enviroment I am using and in my __construct
I load the appropriate config file.
Basically I have 3 questions:
a) should I use Zend_Config or is there any better way?
b) which format should I use? ini or xml? The parameters can be
numbers, strings or mixed arrays
c) If I use Zend_Config I am planning something like the snippet
below. Any advice on using it or a smarter way?
.../blog/application/<models,views,controllers>
.../blog/application/config/devel.xml, stagging.xml production.xml
index.php
...
if(some tests do define the environment as devel)
Zend_Registry::set('ENVIRONMENT','devel')
elseif(some tests do define the environment as stagging)
Zend_Registry::set('ENVIRONMENT','staggingl')
else
Zend_Registry::set('ENVIRONMENT','production')
blog/IndexController.php
class Blog_IndexController
{
function indexAction()
{
... throw an Exception if the environment is not defined...
$blog = new Blog(...,Zend_Registry::get('ENVIRONMENT');
}
}
Blog.php
class Blog
{
function __construct(...,$environment)
{
$config = new
Zend_Config(/path_to_module/config/".$environment.".xml") ;
}
}
Thanks.