Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
help me understand how to use fuel-nestedsets package
  • can someone post a example how to use this package https://github.com/WanWizard/fuel-nestedsets i downloaded the package changed config to autoload
    i created the table using the provided structure then created a model
    <?php
    class Model_Test extends \Nestedsets\Model {
    
     protected static $_table_name = 'test';
    
     public static $tree = array(
      'left_field'     => 'left_id',  // name of the tree node left index field
      'right_field'    => 'right_id',  // name of the tree node right index field
      'tree_field'     => null,   // name of the tree node tree index field
      'tree_value'     => null,   // value of the selected tree index
      'title_field'    => null,   // value of the tree node title field
      'symlink_field'  => 'symlink_id', // name of the tree node tree index field
      'use_symlinks'   => false,   // use tree symlinks?
     );
    }
    

    now if i try something like $mytest = Model_Test::tree_new_root(); i get ErrorException [ Error ]: Call to undefined method Controller_Welcome::is_new() not sure if i understand correctly how to create a model and use it
  • I haven't understand on how to use this package ... exists any complete example?
  • Shon M wrote on Saturday 13th of August 2011:
    I'm sure it would work if you change masterid to tree_id (default).
    In the example the table's "id" has been replaced by masterid, and the treenode id is still called "tree_id". But in the definition, "masterid" is defined as the "tree_field' column, which is incorrect.
  • Davide Bellini wrote on Monday 19th of September 2011:
    I haven't understand on how to use this package ... exists any complete example?
    I don't have any documenation ready, as the package is still in alpha stage. Functionally, it is loosly based on http://www.edutech.ch/contribution/nstrees/. My CI's Datamapper library contains an extension that works similar, maybe that might be of some help: http://datamapper.wanwizard.eu/pages/extensions/nestedsets.html.
  • hmm
    i tried that and i still get a error
    Fuel\Core\Database_Exception [ 1048 ]: Column 'tree_id' cannot be null
    [ INSERT INTO `nstest` (`masterid`, `left_id`, `right_id`, `tree_id`, `symlink_id`) VALUES (5, 1, 2, NULL, NULL) ]
    
    the model
    class Model_nstest extends \Nestedsets\Model &#123;
    
     protected static $_table_name = 'nstest';
    
     public static $tree = array(
      'left_field'     => 'left_id',  // name of the tree node left index field
      'right_field'    => 'right_id',  // name of the tree node right index field
      'tree_field'     => 'masterid',   // name of the tree node tree index field
      'tree_value'     => null,   // value of the selected tree index
      'title_field'    => null,   // value of the tree node title field
      'symlink_field'  => 'symlink_id', // name of the tree node tree index field
      'use_symlinks'   => false,   // use tree symlinks?
     );
    }
    
    in the controller
    $nstest = Model_nstest::factory();
    $nstest->tree_new_root();
    
    the dbtable is empty
    

    i have to call something else first or ?
    can you please post a small example (if is not to much trouble) using multiple trees in on table add delete etc
  • I'm sure it would work if you change masterid to tree_id (default).
  • The package is still in active development, so it could be that things don't work as expected. The issue here is that you're calling tree_new_root() statically, which you can't, it's an object method. Because of the way you call it, $this (in the model class) doesn't point to the model instance, but to the calling class instance, which is your controller.
    In fact, none of the nestedsets methods work statically. It works like this:
    $model = Model_Test::factory();
    $model->tree_new_root();
    
    // now $model contains the root of your new tree
    
  • thanks for your help
    is a great package to have
    i will test and report any problems i find
  • Thanks, it's always handy to have someone else test it as well. p.s. I'll move this thread to the "Code Share" forum, where it belongs...
  • ty @wanWizard
    if i try to use tree_new_root();
    i get
    Fuel\Core\Database_Exception [ 1048 ]: Column 'tree_id' cannot be null [ INSERT INTO `test` (`left_id`, `right_id`, `tree_id`, `symlink_id`) VALUES (1, 2, NULL, NULL) ]
    not sure if you know about it
  • Looks like you haven't configured your models 'tree_field'. If your table contains multiple trees, you will have to define which column contains the tree id. So your configuration could contain that:
    class Model_Page extends \Nestedsets\Model {
    
      * @var custom nestedsets model tree properties
      */
     public static $tree = array(
      'tree_field'     => 'site_id',
      'title_field'    => 'name',
     );
    
    
    Here you see my pages table contains a tree id column called 'site_id'.

Howdy, Stranger!

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

In this Discussion