CTreeView

Apparently I am missing something.

I cannot get the CTreeView to display anything.

I started with Yii 1.4(jquery 1.4.2) then installed Yii 1.5(jquery 1.4.4).

this is the code in my view.php

<?php

$this->widget(‘CTreeView’,

		  array('url' =&gt; array('ajaxFillTree'))

);

?>

this is the code in my controller

public function actionAjaxFillTree()


{

echo"[

{ 


    'text': '1. Pre Lunch (120 min)', 


    'expanded': true, 


    'classes': important'


}, 


{ 


    'text': '2. Lunch  (60 min)' 


}, 


{ 


    'text': '3. After Lunch  (120+ min)'


} 

] ";

}

I’ve tried a db query result like

echo CTreeView::saveDataAsJson($country);

in my controller… no joy.

What am I missing?

I don’t quite get the meaning of your code. But usually to display CTreeView I use code like this :


 $dataTree = array(

                       array(

                               'text'=>'Grampa', //must using 'text' key to show the text

                               'children'=>array( //using 'children' key to indicate there are children

                                       array(

                                               'text'=>'Father',

                                               'children'=>array(

                                                       array('text'=>'me'),

                                                       array('text'=>'big sis'),

                                                       array('text'=>'little brother'),

                                               )

                                       ),

                                       array(

                                               'text'=>'Uncle',

                                               'children'=>array(

                                                       array('text'=>'Ben'),

                                                       array('text'=>'Sally'),

                                               )

                                       ),

                                       array(

                                               'text'=>'Aunt',

                                       )

                               )

                       )

               );


$this->widget('CTreeView',array(

        'data'=>$dataTree,

        'animated'=>'fast', //quick animation

        'collapsed'=>'false',//remember must giving quote for boolean value in here

        'htmlOptions'=>array(

                'class'=>'treeview-red',//there are some classes that ready to use

        ),

        ));

maybe this code can help?

Hi dears,

How to give the LINK?

thanks

i have same question like perochak, any body can help me?

Smitty, please use code tag (second button to the right) when pasting code examples, so it will be more readable to others.

And about your problem. junxiong pasted you a working example (from Yii Playground, if I’m not mistaken) and it is also working for me. If your own code does not work (you don’t see any Tree) please use the one provided and modify it to your needs. Or double check your code, where you probably made a mistake.

Can you be a little more specific, what do you want to achieve? CTreeView class doesn’t have link property. You must give us more details, so we can try to help you.

Thank you all for your replies. My problem was I didn’t add the ajax function (‘ajaxFillTree’) to my access rules in my controller.

For Trejder:

I have the update image wrapped in an html <a href> in front of my displayed item. when I click on the image it executes the update link. when I click on the + or the dislpayed item it expands.

I had to replace the following code to get a first display :

this :




        $parentId = "NULL";

        if (isset($_GET['root']) && $_GET['root'] !== 'source') {

            $parentId = (int) $_GET['root'];

        }



replaced by :




        $parentId = Yii::app()->request->getQuery('root','NULL');

        $parentId = ($parentId == 'source' ? 'NULL' : $parentId);