public function search($param = array())
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria($param);
$criteria->compare('name',$this->name);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
and the VIEW
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$search->search(array('condition'=>"id <> $model->id and (parentId = $model->id OR parentId IS NULL)")),
'id'=>'item-grid',
'selectableRows'=>2,
'filter'=>$search,
'columns'=>array(
array(
'class'=>'CCheckBoxColumn',
'id'=>'chk',
'checked'=>'$data->parentId',
),
'name',
)
));?>
But my condition is incomplete, It show me the parent root and I need to exclude this root parent.
How can I modify my code to exclude the root parent ?
Because If I select the root parent it will be a mess, infinite loop
'dataProvider'=>$search->search(array('condition'=>"id <> $model->id and (parentId = $model->id OR parentId IS NULL)")),
to and add this line on search function
$criteria->condition ="id <> $model->id AND (parentId = $model->id OR parentId IS NULL)"
i think your condition was right but in your case you can write the condition on gridview so every time your query execute so it’s may be infinite loop.
My condition is correct I know, but it is incomplete because with this condition I can Attach the root parent to the last child of a tree and I don’t know how to avoid that.
Can you help me ?
-A
–B
—C
-D
–E
—F
-G
-H
Suppose we are looking the item C, the item C with my condition can attach "A" (wrong), D, G and H.