I started the implementation, and the recursive search is practicly ready. I have one problem though. Each recursive step is a new query with a new CActiveDataProvider. How can i collect the data from multiple dataproviders, to give over to, let’s say the CListView widget? My searches so far point to the conclusion, that there is no way to “merge” dataproviders.
I am sure it is my lack of experience, but i don’t really get your advice. Mabe my post wasnt clear enough. Here is a bit of my code:
public function actionRecQuery($dataProvider)
{
$temp=$dataProvider->getData();
$i=0;
while($temp[$i]['childName']){
$condition='parentName='.'"'.$temp[$i]['childName'].'"';
$dataProvider=new CActiveDataProvider('ViewDepC',array('criteria'=>array('condition'=>$condition,),));
$i++;
$this->actionRecQuery($dataProvider);
}
}
As you can see, the action actionRecQuery is called recursively. Each iteration creates a $dataProvider which is overwritten in the next call. I would like to collect these $dataProviders into one "finalDataProvider" and send it to a viewfile, where i can feed it to a CListView widget.
My approach is probably preatty brute, but thats all i have. I await your advice!
I keep recommending nestedsetbehavior, but if you’d like to collect descendant records by recursion i suggest the following:
No need to instantiate a new CActiveDataProvider on every query. You can use ViewDepC::model()->findAllByAttributes() to retrieve all children of a parent, and collect all records (parents and all of their descendants) in a simple array by using array_merge(). When done, instantiate a CArrayDataProvider with this array and pass it to CListView. Don’t forget to cache the result because - as you probably know - this approach can lead to a large number of queries on every request.
Using findallByAttributes, i array_merged the results in a final array. Then i created a CArraydataProvider
$dataProvider= new CArrayDataProvider($dataArray);
CListView however doens’t like this dataprovider. It keep looking for the ‘id’ property of the model. I am not sure if the ‘id’ property is burried somewhere in the pregenerated code, or i am missing something very basic. Iam aware, that the CArrayDataProvider constructor can have further parameters, i can’t seem to find a proper documentation for it. What could be the problem?
I am sure my questions are getting vaguer and more annoying, thanks for baring with me!