Hej mam male pytanie mam taka oto tablice:
$configs['plugins_settings'] = array( 'compatible' => array('comment', 'polling'), 'description' => 'Czytamy news-a',
'settings' => array('segment_ref' => 0), 'actions' => array('submit', 'delete') )
)
),
'description' => 'Usuwamy news-a',
'settings' => array('segment_ref' => 3), 'actions' => array('submit', 'delete') )
)
)
)
);
A w xml mam to tak:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<plugins_settings>
<compatible>
<plugin>comment</plugin>
<plugin>polling</plugin>
</compatible>
<after>
<readNews>
<description>Czytamy news-a</description>
<plugins>
<comment>
<settings>
<segment_ref>0</segment_ref>
<actions>
<action>submit</action>
<action>delete</action>
</actions>
</settings>
</comment>
</plugins>
</readNews>
</after>
</plugins_settings>
</config>
I teraz chodzi mi dokladnie o sekcje <plugin></plugin> i <action></action>
I mam taki kod ktory to daje do tablicy php:
<?php
/**
*Volta framework
*@author marcio <opi14@op.pl>, <polishvodka7@gmail.com>
*@copyright Copyright (c) 2012, marcio
*@version 1.0
*/
require_once(DIR_INTERFACES.'IConfig.php');
class Vf_Config_Xml_Adapter_Exception extends Exception { }
class Vf_Config_Xml_Adapter implements IConfig
{
public function load($config_path)
{
{
$xml = new SimpleXMLElement($config_path, 0, true);
return $this -> _XmlToArray($xml);
}
else
{
throw new Vf_Config_Xml_Adapter_Exception("Nie zaladowano konfiguracji: ".$config_path);
}
}
public function isAcceptSuffix($suffix)
{
if($suffix == 'xml')
return true;
return false;
}
private function _XmlToArray($xml_object)
{
if(is_object($xml_object) && $vars = get_object_vars
($xml_object)) {
foreach($vars as $key => $value)
{
{
$config[$key] = $value;
}
else
{
$config[$key] = $this -> _XmlToArray($value);
}
}
return $config;
}
return $xml_object;
}
}
?>
Rezultat jest dobry oprocz tych 2 sekcji zwraca mi(czesc tablicy zwiazana tylko z tymi sekcjami):
Cytat
Array ( [plugin] => Array ( [0] => comment [1] => polling )
Array ( [action] => Array ( [0] => submit [1] => delete ) )
A chcialbym miec:
Cytat
Array ( [0] => comment [1] => polling )
Array ( [0] => submit [1] => delete )
A dodaje mi nazwe seksji i potem tablice.
Myslalem to zrobic na 2 sposoby:
1)Sprawdzac czy dana sekja ma wiecej elementow jesli tak iterowac po niej i dawac $key => $value do tablicy
2)Zamiast:
<plugin>comment</plugin>
<plugin>polling</plugin>
Zrobic:
<plugin key="0">comment</plugin>
<plugin key="1">polling</plugin>
I czytac wartosci atrybutu key
Czy idzie to zrobic w prostszy sposob?