arrays using with PEAR::Tree
| From: | Wolfram Kriesing | Date: | Tue, 29 Oct 2002 14:09:29 +0000 |
| Subject: | arrays using with PEAR::Tree | ||
| Groups: | php.pear.dev php.pear.general | ||
| Request: | Send a blank email to pear-dev+get-10322@lists.php.net to get a copy of this message | ||
i remember there was a short thread a while ago, about some kind of trees saved in an array that someone wanted to submit a class for.
i only wanted to show a tiny example of how the Tree class can be used for that. i am building all my navigations using the following way:
$naviItems = array(
array( 'name' => 'User',
'children'=> array(
array('name' => 'Logout',
'condition'=> $userAuth->isLoggedIn(),
'url' => '/modules/user/logout.php'
),
array( 'name' => 'Login',
'condition'=> !$userAuth->isLoggedIn(),
'url' => '/index.php'
)
)
)
);
$navi = Tree::setup('Memory_Array', array('children'=>$naviItems) );
$navi->setup();
$myNaviItems = $navi->getNode();
----- and inside the template/page you can do this ----
foreach( $myNaviItems as $aItem )
{
// show only allowed navi items
if( $aItem['condition'] )
continue;
if( $aItem['url'] )
echo '<a href="'.$aItem['url'].'">'.$aItem['name'].'</a>';
else
echo $aItem['name'];
echo '<br>';
}
i guess this is kinda easy to understand
now you can imagine to write a navi-class which wraps around this and handles stuff like
- permissions/condition
- additional url-addOns
- onClick parameters, which only make
i.e. <a href="javascript://" onClick="theValue">
- automatic folding/unfolding, etc.
if this is a concept/package someone wishes to see in pear, i would be glad to have started something like that ...
ideas are welcome
--
Wolfram
... translating template engine ....
http://sf.net/projects/simpletpl
... authentication system ....
http://sf.net/projects/auth