What about the proposal for Zend Defaults? (nudge, nudge) :)
It would neatly solve this problem by accepting a config object or
array and integrate each component's default values.
http://framework.zend.com/wiki/display/ZFPROP/Zend_Defaults+-+Gavin+Vess
Woops! No, you're absolutely right, you need to use $config-
>database->params->toArray().
I always make that mistake in my own code too. I'll just have to
modify Zend_Db to accept a Zend_Config object and automatically do
the right thing. :-)
Regards,
Bill Karwin
From: AmirBehzad Eslami [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 19, 2007 6:33 PM
To: Bill Karwin
Cc: [email protected]
Subject: Re: [fw-general] [ZF-General] Reading from XML file using
ConfigXML
Bill Karwin wrote:
$db = Zend_Db::factory($config->database->type, $config->database-
>params);
I'm unable to run the code, It seems that
you forgot to convert <params> from an object
to an array. Or perhpas I'm missing something?
On 7/20/07, Bill Karwin <[EMAIL PROTECTED]> wrote:
I would organize my config like this:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<production>
<database>
<type>mysqli</type>
<params>
<host>localhost</host>
<port>3306</port>
<username>root</username>
<password></password>
<dbname></dbname>
</params>
</database>
<debug>TRUE</debug>
</production>
</config>
Then it's easy to use like this:
$db = Zend_Db::factory($config->database->type, $config->database-
>params);
Regards,
Bill Karwin
From: AmirBehzad Eslami [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 19, 2007 5:50 PM
To: [email protected]
Subject: [fw-general] [ZF-General] Reading from XML file using
ConfigXML
Hi,
Suppose we have an XML file like the following one:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<production>
<database type="mysqli">
<host>localhost</host>
<port>3306</port>
<username>root</username>
<password></password>
<dbname></dbname>
</database>
<debug>TRUE</debug>
</production>
</config>
Note that the 'database' has a 'type' attribute.
How can I read the type attribute of database?
$config = new Zend_Config_Xml('./application/config.xml',
'production', FALSE);
echo($config->database->sec->value); // returns NULL
echo($config->database->sec); // returns NULL
Both return NULL!
--
Simon Mundy | Director | PEPTOLAB
""" " "" """""" "" "" """"""" " "" """"" " """"" " """""" "" "
202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654
4124
http://www.peptolab.com