Pet*_*mit 5 php configuration zend-framework zend-application
我正在使用Zend_Application,我觉得我在application.ini混合应用程序和用户配置感觉不对.
我的意思是以下内容.例如,我的应用程序需要名称空间MyApp_中的一些库类.所以在application.ini中我放了autoloaderNamespaces [] ="MyApp_".这是纯粹的应用程序配置,除了程序员之外没有人会更改这些.另一方面,我把数据库配置放在那里,这是SysAdmin会改变的.
我的想法是我会在application.ini和user.ini之间拆分选项,其中user.ini中的选项优先(因此我可以在application.ini中定义标准值).
这是一个好主意吗?我怎样才能最好地实现这一点?我的想法是
我该怎么办?我希望有一个"最干净"的解决方案,为未来做好准备(较新的ZF版本,以及其他开发人员在同一个应用程序上工作)
Tro*_*roy 10
我找到了这个问题的解决方案,可能是框架版本1.10的新功能.创建Zend Application对象时,可以在两个合并在一起的options数组中传入2个配置文件路径:
$application = new Zend_Application(
APPLICATION_ENV,
array(
'config' => array(
APPLICATION_PATH . '/configs/application.ini',
APPLICATION_PATH . '/configs/user.ini'
),
)
);
Run Code Online (Sandbox Code Playgroud)
小智 6
你知道这会合并你想要的inis吗?
在application.ini中
[production]
config[] = APPLICATION_PATH "/configs/dsn.ini"
config[] = APPLICATION_PATH "/configs/error.ini"
...
Run Code Online (Sandbox Code Playgroud)
这没有什么不对,我做了类似的事情.我建议使用你的第二选择.我只有一个_initConfig()方法,负责使用Zend_Config_Ini加载用户配置.我不会扩展Zend_App,这似乎有点多.
在回复您的评论时,您只需:
$this->bootstrap('config');
Run Code Online (Sandbox Code Playgroud)
因此,为了确保在DB之前加载配置,您将拥有如下内容:
protected function _initConfig()
{
$config = new Zend_Config_Ini('/path/to/user.ini');
return $config;
}
protected function _initDb()
{
$this->bootstrap('config');
$config = $this->getResource('Config');
/* ... */
}
Run Code Online (Sandbox Code Playgroud)
没有必要使用Zend_Registry,因为可以使用getResource()访问Bootstrap _init方法返回的任何内容.