Issues

ZF-5973: iterating over a Zend_Config

Description

having a configuration file like this one :


<?xml version="1.0" encoding="UTF-8"?>
/tmp/bla.log
logtimestamppriorityNameprioritymessageuserphp://output

this code fails quite well :


$config = new Zend_Config_Xml('/config/log.xml');
foreach ($config->writer as $writerCfg) {
    $writers[$writerCfg->name] = InnoPrim_Log_Writer_Factory::build($writerCfg);
}

the first writerCfg element is "file", which quite not what I asked for.

did I do something wrong?

Comments

ok, a new to do it is describe here: http://blog.riff.org/2007_03_19_multiple_entries_w…

The reason for this is, that the second level is seen as section-level, which cannot be folded into an array. You have to make your config look something like this:


<?xml version="1.0" encoding="UTF-8"?>
/tmp/bla.log
logtimestamppriorityNameprioritymessageuserphp://output

Then you can iterate over them like this:


foreach ($config->writers->writer as $writerCfg) {
    $writers[$writerCfg->name] = InnoPrim_Log_Writer_Factory::build($writerCfg);
}

I tried to iterate it but iterated on $config->writers

sorry to have bothered you.

Thanks a lot for you help!