Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Questions how to use fuel-nestedsets package
  • Hello,

    I try to understand how the fuel-nestedsets package is working and what I need to do in fuel to use it.

    What I have understood so far is the following. I will use this with Multiple Trees. So I made one Model "Metatree" which contains the IDs and Names of the different trees:
    http://snipr.it/~CC

    Then I have the Model "Tree" which contains the single nodes. For using Multiple trees I set 'tree_field'     => 'tree_id', as this field will contain the IDs from the Model "Metatree":
    http://snipr.it/~CD

    Up to now, I have no field for the name of the node. Will extend this later. But this will also be in the tree table.

    What I understood so far is the following:
    To create a new tree I need to
    1) Create a new Object of type "Tree"
    2) Select the ID from the Model "Metatree"
    3) Pass this ID to function "tree_select"
    4) Create the new tree object with function "tree_new_root"
    Here is my complete Code:
    http://snipr.it/~CE

    I assumed that the selected ID from Model "Metatree" is stored as "tree_id" in the Model "Tree", which actually doesn't work, as "tree_id" is always set to the next free number like an AutoIncrement field.

    If I check the two functions in the package I see that while selecting "tree_value" is used and while building new rootm, then "tree_field" is checked for duplicates. Is that the reason this is not working???

    Don't know if I understnd the way I need to do something correctly.
    Perhaps somehone can help me in that matter.

    Thanks Kay


  • tree_new_root() generates a new tree root with a unique tree id, so it you use a second table to create your tree id's, you should not use that method, but create the root node manually:

    $tree = Model_Tree::forge(array(
        'left_id' => 1,
        'right_id' => 2,
        'tree_id' => $your_meta_tree_id;
    ));
    $tree->save();
  • ok, understood

    Let's say for a moment I don't want to use two models, only one Model "Tree".

    If I then want to add a new tree, I only need to set the name for it and call $tree->tree_new_root(); ???
    Tried this, but "name" (Value of the tree) is always empty. Here is my code:

        public function action_createtree()
    {

    if (\Input::method() == 'POST')
    {
    \Debug::dump(\Input::post()); #die;
    $tree = \Metadata\Model_Tree::forge();
    $tree->tree_new_root();
    \Debug::dump($tree); die;
    }

    return \Theme::instance()
    ->get_template()
    ->set( 'content',
    \Theme::instance()->view('admin/meta/createtree')
    );
    }


    Thanks Kay
  • tree_new_root() only sets left, right and tree id's. It doesn't touch anything else in the object.
  • ok and how can I then add new values, like "name"?
  • $tree->name = 'Value';

    like for any other (ORM) object ?

Howdy, Stranger!

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

In this Discussion