[eluser]donald.tbd[/eluser]
Hello, i have 3 questions about creating a menu tree with codeigniter.
First of all ill explain how i do it at a moment.
First I select every entery from db, i get item id, parent_id and title from there. If the parent_id is 0 then its a main item, if its something else it belongs under another parent item.
Secondly i print out the main items like this:
Code:
<?php
foreach($data AS $item){
if($item->parent_id == 0){
print $item->title;
get_subs($data, $item->id);
}
}
?>
Thirdly as you can see after every main item i call function get_subs()
The function looks like this:
Code:
<?php
function get_subs($data, $parent_id){
foreach ($data as $item) {
if($item->parent_id == $parent_id){
print $item->title;
get_subs($data, $item->id);
}
}
}
?>
And again as you can see i check if there are any items to current main item and print them out.
Now my three questions are:
1) Holding functions in a view seems kind of wrong in CI. But i cant find a better place for this?
2) I want to create a hierarchy or a tree somehow that every sub item is a bit further away from main element. How to do that?
3) Is there a better way to handle all of this? Maybe CI offers seme good helper functions i dont know about?
Thanks for reading/replying!
Donald.