Config_Container::searchPath()

Config_Container::searchPath() -- Finds a node using XPATH like format

概要

require_once 'Config/Container.php';

mixed Config_Container::searchPath (mixed $args)

説明

This method tries to find an item by following a given path from the current container.

This method can only be called on an object of type 'section'. Note that root is a section. This method is recursive.

This method takes as many parameters as is needed to define your path to the requested item. The format is array (item1, item2, ..., itemN). Items can be strings or arrays. Strings will match the item name, while arrays will match 'name' and/or 'attributes' properties of the requested item.

パラメータ

mixed $args

Strings or arrays of item to match in the order they will be matched, separated by commas

返り値

mixed - reference to item found or FALSE when not found

注意

この関数は、スタティックにコールする ことはできません。

例 31-1Example for searchPath() usage


<?php
// Let's say our XML configuration looks like this:

// <config>
//   <db>
//     <user>root</user>
//     <password>pass</user>
//     <host>localhost</host>
//   </db>
// </config>

$config = new Config();
$root =& $menuObj->parseConfig('db.xml', 'xml');

// Will return the password directive in db
$passObj =& $root->searchPath(array('config', 'db', 'password'));
?>

例 31-2More complex example with attributes for searchPath()


<?php
// Let's say our XML configuration looks like this:

// <menu>
//   <group id="company">
//     <page id="news"/>
//     <page id="jobs"/>
//   </group>
//   <group id="projects">
//     <page id="project1"/>
//     <page id="project2"/>
//   </group>
// </menu>

$menuObj = new Config();
$root =& $menuObj->parseConfig('menu.xml', 'xml');

// Will return the container in menu which 'id' is set to 'projects'
$section =& $root->searchPath(array('menu', array('group', array('id' => 'projects'))));

// To get a page we could also use
$page =& $root->searchPath(array('menu',
                                  array('group', array('id' => 'projects')), 
                                  array('page',  array('id' => 'project2'))));
?>