[size="5"]In your relation[/size]:
‘parent’ => array(self::BELONGS_TO, ‘Yiicms’, ‘parent_title’, ‘condition’ => ‘t.parent_title = 0’),
'children' => array(self::HAS_MANY, 'Yiicms', 'parent_title'),
'childCount' => array(self::STAT, 'Yiicms', 'parent_title'),
:
:
public static function getParent($id)
{
$title = self::model()->findByPk($id);
//echo '<pre>';
//print_r($title); exit;
return $title['title'];
}
And your controller:
public function actionAjaxFillTree()
{
// accept only AJAX request (comment this when debugging)
if (!Yii::app()->request->isAjaxRequest) {
exit();
}
// parse the user input
$parentId = "NULL";
if (isset($_GET['root']) && $_GET['root'] !== 'source') {
$parentId = (int) $_GET['root'];
}
// read the data (this could be in a model)
$children = Yii::app()->db->createCommand(
"SELECT m1.id, m1.title AS text, m2.id IS NOT NULL AS hasChildren "
. "FROM tree AS m1 LEFT JOIN tree AS m2 ON m1.id=m2.parent_id "
. "WHERE m1.parent_id <=> $parent_title "
. "GROUP BY m1.id ORDER BY m1.name ASC"
)->queryAll();
echo str_replace(
'"hasChildren":"0"',
'"hasChildren":false',
CTreeView::saveDataAsJson($children)
);
}
in your admin page:
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'yiicms-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'title',
'content',
//'parent_title',
array('name'=>'parent_title',
'value'=> 'Yiicms::getParent($data->parent_title)'),
array(
'class'=>'CButtonColumn',
),
),
));
i don’t know what you r expectin but try this becoz this is my training project i got good result