Jan 27 2008
CakePHP and EXTJS tree
Hi all!
I had to insert a tree in order to edit the structure of a menu. I found out that extjs tree are great! It lets you add a tree with dynamic content and move node from the root to leafs. So I tried integrating it, it’s really easy.
I added a js function to the tree javascript (from the reorder example in the extjs package)
function getTreeContents(tree) {
return getNodeContents(tree.root,true);
}
function getNodeContents(node) {
var s = ”;
if(node.childNodes.length > 0)
{
for(var i=0; i<node.childNodes.length; i++) {
s+= node.id+’-'+node.childNodes[i].id +’|';
s += getNodeContents( node.childNodes[i],false);
}
}
return s;
}
This returns a list of parentid-childid which, everytime the tree is changed, I add to a hidden textbox. Then I get the value of this textbox in the controller code, parse it and update all the nodes according to passed values.
That’s it!


Default
Small Fonts
Big Fonts