Question

I used CTreeView in Yii framework because I want to show a list of users. all users are shown in my tree but I want to add css to a node that i am reading node's information.
For example: if i go to user/view/[id], tree are shown by all users Whereas user by [id] is highlight how can do it?

controller:

 public function actionAjaxFillTree()
{
    // accept only AJAX request (comment this when debugging)
    if (!Yii::app()->request->isAjaxRequest) {
        exit();
    }
    // parse the user input
    $parentId = Yii::app()->user->id;
    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.username AS text, m2.id IS NOT NULL AS hasChildren "
        . "FROM psh_users AS m1 LEFT JOIN psh_users AS m2 ON m1.id=m2.parent_id "
        . "WHERE m1.parent_id <=> $parentId "
        . "GROUP BY m1.id ORDER BY m1.username ASC"
    )->queryAll();

    echo str_replace(
        '"hasChildren":"0"',
        '"hasChildren":false',
        CTreeView::saveDataAsJson($children)
    );
}  

view:

<?php
$this->widget(
    'CTreeView',
    array('url' => array('ajaxFillTree'),

        )
);
?>
</div>

No correct solution

OTHER TIPS

i could highlight the node that related page :

 public function actionAjaxFillTree() {
    // accept only AJAX request (comment this when debugging)
    if (!Yii::app()->request->isAjaxRequest) {
        exit();
    }
    $node = $_GET[id];
    // parse the user input

    $parentId = Yii::app()->user->id;
    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.username AS text, m2.id IS NOT NULL AS hasChildren "
                    . "FROM psh_users AS m1 LEFT JOIN psh_users AS m2 ON m1.id=m2.parent_id "
                    . "WHERE m1.parent_id <=> $parentId "
                    . "GROUP BY m1.id ORDER BY m1.username ASC"
            )->queryAll();
    $treedata = array();
    foreach ($children as $child) {
        $options =  ($child['id'] == $node)? array('href' => '#', 'id' => $child['id'], 'class' => 'treenode selected_node'):
        array('href' => '#', 'id' => $child['id'], 'class' => 'treenode');
        $nodeText = CHtml::openTag('a', $options);
        $nodeText.= $child['text'];
        $nodeText.= CHtml::closeTag('a') . "\n";
        $child['text'] = $nodeText;
        $treedata[] = $child;
    }
    echo str_replace(
            '"hasChildren":"0"', '"hasChildren":false', CTreeView::saveDataAsJson(**$treedata**)
    );
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top