How to load more resources which are out of the application env?
I have a application.ini like this
[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[database]
resources.db.adapter = PDO_MYSQL
resources.db.params.dbname = "ccgss"
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.hostname = "localhost"
resources.db.isDefaultTableAdapter = true
[layout]
layoutPath = APPLICATION_PATH "/layouts"
layout = default
contentKey = "content"
By default, zend framework loads the [production]
section. How do I load automatic开发者_开发百科ally the others sections?
Additionally
How do I change the environments between staging
, testing
, development
and on?
To switch your application's environments between production, development, etc. simply set the variable to appropriate value in your .htaccess
file:
SetEnv APPLICATION_ENV development
If you'd like to auto-load your own resource plugins from the bootstrap, you can do that by just tacking it onto the resources
array:
resources.myplugin.param1 = "myvalue"
Don't forget to add your plugin's namespace and directory path to the pluginsPath
value as well, or ZF won't know where to look:
pluginPaths.My_Resource_Namespace = "My/Namespace/Folder"
Finally, if you want to acces values in your config file without using a resources
plugin, you can load the file using the Zend_Config_Ini class:
$config = new Zend_Config_Ini('/path/to/config.ini', 'staging');
Zend Framework loads 'production' section because your environment is set to 'production' in your index.php
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
So to change your environment to something other than production, you simply need to change value of APPLICATION_ENV
variable (you can do this in .htaccess for instance).
Besides, you probably don't need separate sections for database and layout, just include them into 'production' section. If you use separate sections for them, they are not parsed because only the current environment section is parsed, as you can see from this line
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
精彩评论