Welcome Guest, Not a member yet? Register   Sign In
Hieratic Category Query
#11

[eluser]lightnb[/eluser]
Would it make sense then to have a root that isn't actually the root of the tree, but a logical device that exists for the sole purpose of tree integrity?

In other words, a root node, manually inserted, that never actually gets displayed or used in the application for any reason?
#12

[eluser]lightnb[/eluser]
So the demo/Library works if the root is left alone. But I'm still very confused as to how the library integrates with my existing application.


For insertion:
My controller has the name of the new node as a string, and the UID of the parent node as an int.

The Controller then calls the "AddNewCategory" method of my model.

Code:
function AddNewCategory($NewCatName, $ParentCatID)
    {    
         // Somehow the "insertNewChild" method of the "Nested Sets" library gets called here...
             // Can I just stick it here??
    }
#13

[eluser]esra[/eluser]
[quote author="lightnb" date="1205644714"]Would it make sense then to have a root that isn't actually the root of the tree, but a logical device that exists for the sole purpose of tree integrity?

In other words, a root node, manually inserted, that never actually gets displayed or used in the application for any reason?[/quote]

With nested sets, you need a parent root node as the basis of each hierarchy. All MPTT or MIPTT queries are based on the existence of a root node. However, this does not mean that a single table could not store multiple hierarchies, each with their own root. You could create a second table called trees and add a foreign key to the hierarchies table to associate hierarchies of nodes with different trees (roots). Then it's possible to clone (copy) an existing hierarchy and append it to another hierarchy (tree) with a different foreign key. In this case, you could think of the hierarchies table itself as a root of all hierarchies (trees) contained within that table.

There are some other approaches to handling this based on the use of a level column, making it easier to copy and move branches of a tree about.

http://www.phpriot.com/articles/nested-trees-1
#14

[eluser]lightnb[/eluser]
I might be getting closer...

I'm now getting:

Quote:An Error Was Encountered

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

UPDATE Forums_Categories SET LeftID = LeftID + 2 WHERE LeftID >=

and using this code in the controller:
Code:
$this->load->model('Nested_sets_model', 'cats');
$this->cats->setControlParams('Forums_Categories', 'LeftID', 'RightID');      
              
$parentNode = $this->cats->getNodeFromId($this->validation->ParentCat);
        
$fields_array = array("categoryname"=>$this->validation->NewCatName);
$this->cats->appendNewChild($parentNode,$fields_array);

It looks like the query isn't getting finished?




Theme © iAndrew 2016 - Forum software by © MyBB