[eluser]Taff[/eluser]
I am rewriting some code I have inherited and need to get create a tree type class.
Currently the class calls a new instance of itself to create a child "branch" i.e. it recursively creates a full tree. How would I do this in CI? I currently have a Match class that is calling the MatchingNode class like this:
Code:
//Load the node
$CI =& get_instance();
$CI->load->library("MatchingNode",$cat);
$rootNode = $CI->matchingnode->getNodeName();
which works perfectly.
In my MatchingNode.php class I have a function that I will be calling for each child.
It looks like this:
Code:
//Ideally I would like to loop through an array and create a new instance for each child.
function fillChildrenNodes(){
$CI = & get_instance();
$CI->load->model('nodemodel');
//Get some numbers from the database
$tmp = $CI->nodemodel->fill_child_nodes($this->nodeId);
//Returns the array as I would expect
$this->nodeSize = sizeof($tmp);
//Loop through the array...
for($i = 0;$i < $this->nodeSize;$i++){
//THIS IS WHERE THE PROBLEM IS
$A1 = &get;_instance();
$param = $tmp[0]['KAT_ID'];
//Echos out correctly
echo "<br />Child: ".$param;
//Reload the library passing it a different parameter...no error
$A1->load->library("MatchingNode",$param);
//I should have received an output loading...file_id for each child.
}
}
Now normally I would have just done:
Code:
for($i=0; $i < $size; $i++){
$row = mysql_fetch_assoc($result);
//The old fashioned way
$nextChild = new matchingNode($row[KAT_ID]);
$nextChild -> setNodeName($row[KAT_NAME]);
$nextChild -> setParentNodeId($this -> nodeId);
array_push($this -> childrenNodes, $nextChild);
echo $this->childrenNodes;
}
Can anyone point me in the right direction?
Thanks,
Taff