Ctreeview Data From Multiple Related Tables


I have 3 tables that I am trying to populate a ctreeview widget with. The tables are company HAS MANY sites HAS MANY Users.

I am assuming that I need to get an array back from the query but looking at some of the other extensions I cant seem to grasp how that is done.

Any help would be great.

Sorry for the lack of info but its late and the mind is struggling to engage.


Normally a treeview is displaying data from only one table. But you should be able to use three tables, because - as you said - you only need to compile an array with the correct data.

Have a look at XTreeBehavior (used in Yii-Playground and downloadable from github).

It only uses 1 table at a time, but you should be able to amend it.


this is a exm :

in view











in controller

 public function actionAjaxFillTree()


        // accept only AJAX request (comment this when debugging)

        if (!Yii::app()->request->isAjaxRequest) {



        // parse the user input

        $parentId = "0";

        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 tel_job AS m1 LEFT JOIN tel_job AS m2 ON m1.id=m2.parent "

            . "WHERE m1.title!='-' and m1.parent <=> $parentId "

            . "GROUP BY m1.id ORDER BY m1.title ASC"



        echo str_replace(