dsdvr06648 2011-01-06 09:04
浏览 51
已采纳

Zend application.ini

I'd prefer to use native php for Zend configuration. How would I convert this Zend application.ini segment into php?

[development : production]

production section supposedly inherits from development section. P.S we are talking about ZEND framework here.

Update: Looks like I wasn't clear with my question.

All I wanted to know was how Zend_Application handles inheritance/nesting in php options file comparing to ini or xml.

INI config example (everything in production section will be inherited by testing and development section):

[production]
autoloaderNamespaces[] = "My_"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"

[testing : production]
bootstrap.class = "productionBootstrap"

[development : production]
bootstrap.class = "developmentBootstrap"

XML config example (everything in production section will be inherited by staging section, note extends keyword):

<?xml version="1.0"?>
<configdata>
    <production>
        <webhost>www.example.com</webhost>
        <database>
            <adapter>pdo_mysql</adapter>
            <params>
                <host>db.example.com</host>
                <username>dbuser</username>
                <password>secret</password>
                <dbname>dbname</dbname>
            </params>
        </database>
    </production>
    <staging extends="production">
        <database>
            <params>
                <host>dev.example.com</host>
                <username>devuser</username>
                <password>devsecret</password>
            </params>
        </database>
    </staging>
</configdata>

PHP config example No inheritance/nesting? Is there a way to make inheritance/nesting work without doing manual array merging?

return array(
    'production' => array(
         $test1 => 'aaaaaaa'
     ),
    'staging' => array(
        $test2 => 'bbbbbb'
    ),
    'testing' => array(
        $test3 => 'bbbbbb'
    )

)

UPDATE

In retrospect - just wanted to add that there are certain advantages to using php arrays instead of ini files for configuration: some info

· they can be cached by an opcode cache

· they support constants

· they allow to create easily readable config trees

· they support boolean and integer values

  • 写回答

2条回答 默认 最新

  • dtu11716 2011-01-06 10:14
    关注

    Iam not sure what you mean, but you can simulate this in your php file with your config like this:

    $configProduction = array(
        'database' => $db1,
        'url'      => 'www.production.com',
    );
    
    $configDevelopment = array(
        'url' => 'www.test.com',
    );
    
    //ENV is set in bootstrap or htaccess or php.ini
    switch (APPLICATION_ENV) {
        case 'production':
            $config = $configProduction;
            break;
        case 'development':
            $config = array_merge($configProduction, $configDevelopment);
            break;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)