I have a table with following structure:
categories
- id
- name
- parent_id
I want to get the tree of categories with single function.
I’ve written something like this in my model, but it doesn’t work.
public function getChildren($parent) {
$criteria = new CDbCriteria;
$criteria->condition='parent_id=:id';
$criteria->params=array(':id'=>$parent);
$model = Term::model()->findAll($criteria);
while ($model) {
echo $model->id . "<br />";
$this->getChildren;
}
}
Can someone help me with this? Thanks.
I’ve finally solved the issue.
If someone interested, here’s the code: