Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
NestedSet: $tree['children'] not working in dump_tree()
  • Dear,

    I cannot fetch children, using dump_tree(), 

    using Debug::dump($tree); provides this http://bin.fuelphp.com/~HV

    Kindly check and reply soon.

    My Controller as follows: http://bin.fuelphp.com/~HW

    So i fetching my Dashboard title using this <?= $sidebar_menu[1]['children'][2]['title']; ?>

    It is working, But i thing the fetching is too complicated. How i do it?
  • HarroHarro
    Accepted Answer
    It's a tree structure, so you need to recurse over it.

    We use this logic to retrieve the tree and display it: http://bin.fuelphp.com/snippet/view/HY

    And it's view looks like this: http://bin.fuelphp.com/snippet/view/HZ

    Note that this is relatively old code, most of the logic in the view should have to go into a Presenter, to keep the view free of code. And it's specific to our application framework, so you might have to adapt it.
  • p.s.: this code produces the accordion main menu on the left: http://i.imgur.com/yc7mFRZ.png
  • I found easy way,

    Firstly i used \Arr::reindex() over the array Dump_tree(). So it created new index starting from 0, 
    So it is easy to create menu using a foreach(). Need very less logic.
  • If you only have one level of menu, that is an option. If your menu has unlimited depth, the only proper way to go over it is recursion.
  • Dear Harro, It is possible,
    I have done that

    http://bin.fuelphp.com/~H3

    i used, this, I getting all menu and also submenu, it it have. Kind reply required.
  • As I said, you can hardcode your loops when you have a known structure.

    Your code will probably work as long as there is only a main menu and one level of submenu's. As soon as you introduce a second submenu level (Menu -> submenu -> sub-submenu), you code fails. You don't have that with recursion. Obviously, your css must be able to support that.

    I can't judge whether or not this is an issue for you, I don't know your application. I just want to be complete in my answer, also for other people finding this thread.
  • Thanks Harro,

    Is there any way to read the max depth of tree?
  • HarroHarro
    Accepted Answer
    Yes: $model->depth();

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion