Welcome Guest, Not a member yet? Register   Sign In
MPTtree, Hieararchical trees in a database table

[eluser]Unknown[/eluser]
[quote author="nardanadam" date="1258495169"]m4rw3r, your solution requires update of 'order' columns of data, when an insert operation is processed.
Do you think it really fits for this situation?[/quote]

Nested sets model implies updating when inserting new records, it is a normal situation.

Say when you want to insert a new item between two existing ones with adjacent (lft, rgt) ranges (e. g. (10, 20) and (21, 30)), you will have to update the range boundaries of the rightmost item and all items to the right of it.

It's like inserting a new node into an XML file: when you do it, all subsequent tags (even those that do not define direct ancestors, siblings or descendants of the node being inserted) are being shifted several lines down.

This can be mitigated to some extent by reserving some extra space when inserting new records (making lft and rgt more sparse).

[eluser]sqwk[/eluser]
Small Bug: On line 745 of mpttree.php (model)

Code:
$this->db->select('title');

should be

Code:
$this->db->select($this->title_col);

[eluser]Unknown[/eluser]
m4rw3r you have done a good job.
I a`m beginner, and I really can`t understand how to build such menu
+Root
|--Main Category 1
| |--Subcat 1
| |--Subcat 2
| | |--Sub-subcat 1
| | |--Sub-subcat 2
| |--Subcat 3
|--Main Category 2
| |--Subcat 4
| |--Subcat 5
| |--Sub-subcat 3
|--Main Category 3
|--Main Category 4
| |--Subcat 6
| |--Subcat 7

What have I do with the functions written by crises???
Would I have to add one of them(function category) to your controller wiki??? and others to the mpttree model???

Thanks for your answer and your work...

[eluser]Gamesh[/eluser]
there is a bug on PHP 5.3
Code:
function debug_message(&$message){

strings can not be passed as reference, as you are creating a string that is not stored in any variable, and this type of declaration has no meaning and doesn't save memory.
this line of code gives fatal error.

[eluser]Unknown[/eluser]
[quote author="Gamesh" date="1294938660"]there is a bug on PHP 5.3
Code:
function debug_message(&$message){

strings can not be passed as reference, as you are creating a string that is not stored in any variable, and this type of declaration has no meaning and doesn't save memory.
this line of code gives fatal error.[/quote]

I've deleted out this, non-working on php 5.3, debug method, changed all getwhere to get_where and library $this->db->select('title'); to $this->db->select($this->title_col); and it's working just fine for me on codeigniter 2.0 php5.3.5

[eluser]Kiddo[/eluser]
hello, i'm new here and i'm also a newbie in CI. i'm interested in using your MPTtree and i would really appreciated it if you can write down some addition code in documentation on how to use it nicely, like a code how to create a tree that can list:

- Root 1
-- Sub 1
--- Sub 1.1
--- Sub 1.2
-- Sub 2
-- Sub 3
- Root 2

and also if i can say, i totally can't get too well on the manual. it's really unfriendly to me. i don't have any idea on how to use the function of MPTtree on manual to fit on with my project....

again and again,
thanks and sorry to bother! ^^

[eluser]jojovem[/eluser]
I extracted the last version of codeigniter. Then i extracted all files included in the latest Preorder Nested Tree functions.

When i tried to execute:

Code:
<?php

class Tree extends CI_Controller
{

     public function index()
     {
        $this->load->model('mpttree');
     }
}


/* End of file tree.php */
/* Location: ./application/controllers/tree.php */

?>


I got the error:
Fatal error: Class 'Model' not found in D:\Server\ci\application\models\mpttree.php on line 143

Then i changed de line 143
FROM:
class MPTtree extends Model{
TO:
class MPTtree extends CI_Model{

Then the error changed to:
Fatal error: Call to undefined method CI_Model::model() in D:\Server\ci\application\models\mpttree.php on line 192

And this one i cant fix it. Can anybody help me?

191 function MPTtree(){
192 parent::model();
193 }

[eluser]WanWizard[/eluser]
How about
Code:
parent::__construct();

[eluser]jojovem[/eluser]
I did that, and it temporary fixed Big Grin

So the problem now is this:

Code:
<?php

class Tree extends CI_Controller
{

     public function index()
     {
        $this->load->model('mpttree');
        $this->mpttree->set_table('Tree');
        $root = $this->mpttree->insert_root(array('TESTE'));
        print_r($root);        
     }
}


/* End of file tree.php */
/* Location: ./application/controllers/tree.php */

?>

Fatal error: Call to a member function query() on a non-object in D:\Server\ci\application\models\MPTtree.php on line 363

Code:
360     function lock_tree_table($aliases = array())
361    {
362        $q = "LOCK TABLE " . $this->tree_table . " WRITE";
363        $res = $this->db->query($q);
364    }

Im sorry, but im really having a battle on this Big Grin

[eluser]WanWizard[/eluser]
MPTree extends CI_Model? And the call to parent::__construct() works? Is the database class loaded and properly defined?

The error is that $this->db is not assigned, which happens in CI_Model through a magic method. Does MPTree define a __get() by any chance that could interfere with that?

You're trying to get a 1.x library to work in 2.x, you might run into all kinds of issues...




Theme © iAndrew 2016 - Forum software by © MyBB