<?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? ); }
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.Shon M wrote on Saturday 13th of August 2011:I'm sure it would work if you change masterid to tree_id (default).
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.Davide Bellini wrote on Monday 19th of September 2011:I haven't understand on how to use this package ... exists any complete example?
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 { 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
$model = Model_Test::factory(); $model->tree_new_root(); // now $model contains the root of your new tree
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'.
It looks like you're new here. If you want to get involved, click one of these buttons!