/**
* Fills the JS tree on an AJAX request.
* Should receive parent node ID in $_GET['root'],
* with 'source' when there is no parent.
*/
public function actionAjaxFillTree()
{
Yii::app()->user->setFlash('success', 'Entrem a actionAjaxFillTree!');
// accept only AJAX request (comment this when debugging)
if (!Yii::app()->request->isAjaxRequest) {
Yii::app()->user->setFlash('success', 'Error a actionAjaxFillTree!');
exit();
}
// read the data (this could be in a model)
$children = Yii::app()->db->createCommand(
"SELECT m1.id, m1.name AS text, m2.id IS NOT NULL AS hasChildren "
. "FROM tree AS m1 LEFT JOIN tree AS m2 ON m1.id=m2.parent_id "
. "GROUP BY m1.id ORDER BY m1.name ASC"
)->queryAll();
echo str_replace(
'"hasChildren":"0"',
'"hasChildren":false',
CTreeView::saveDataAsJson($children)
);
}
The index.php/tree/admin show values in the grid, but I don’t see CTreeView in the form.