Andreas Sundqvist-2 wrote:
> 
> Hi
> 
> I was wondering why you can't get an multi dimension array out of the
> config object
> 
> 
> is this possible. or  can i do this in any other way?
> 
> 

I'm created another Xml class to have this feature you are asking for

<?php

Zend_Loader::loadClass('Zend_Config_Xml');

class My_Config_Xml extends Zend_Config_Xml{

    protected function _toArray($xmlObject)
    {
        $config = array();

        foreach ($xmlObject->children() as $key => $value) {

            if( $value->attributes() ){
              foreach( $value->attributes() as $aKey => $aItem){
                $config[$key]['_attributes'][$aKey] = current($aItem);
              }
            }

            if ( sizeof($value->children()) ) {
                if( $value->attributes() ){
                    $config[$key] =
$this->_arrayMergeRecursive($config[$key], $this->_toArray( $value ));
                } else {
                    if( gettype(current($xmlObject->children())) == 'array'
){
                        $config[$key][] = $this->_toArray($value);
                    } else {
                        $config[$key] = $this->_toArray($value );
                    }
                }
            } else {
                if( !empty( $config[$key] ) ){
                    settype($config[$key], 'array');
                    $config[$key][] = (string)current($value);
                } else {
                    $config[$key] = (string)current($value);
                }
            }
        }

        return $config;
    }

}


Maybe it's not optimized but at least works as I need :)
-- 
View this message in context: 
http://www.nabble.com/Zend_Config_Xml-and-arrays-tf3976269s16154.html#a11503294
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to