Create Multidimensionnal Array For Ctreeview

Hi everybody,

I try to make a multidimensionnal array with my data on my database to create a CTreeview.

Here an exemple :




// CTREEVIEW

<?php

$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

        ),

));

?>






//ARRAY

<?php

$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',

				)

			)

		)

	);?>



The only problem is that I don’t know how to make that kind of multidimensionnal array.

My Table :

Node

id

levelOneId

levelTwoId

levelThreeId

revisionId

Here some crapy code, the problem is showing only the last node :(




<?php

foreach($nodes as $node){

$tree = array(

        array(

            'text' => trim($node->levelOneName),

            'children' => array(

                array(

                    'text' => trim($node->levelTwoName),

                    'children' => array(

                        array(

                            'text' => trim($node->levelThreeName),

                            'children' => array(

                                array(

                                    'text' => CHtml::link(trim($node->revisionName),array('view','id'=>$node->id)),


                                )

                            )

                        )

                    )

                )

            )

        )

    );

}

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

        'data'=>$tree,

        '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

        ),

));

}

?>



Thanks for help

Please nobody could help,

should not be so difficult for some advance developer.

I tried this with no luck :




<?php 

$leveOneId = 0;$leveTwoId = 0;$leveThreeId = 0;

foreach ($nodes as $node) {     

if($node->leveOneId!= $leveOneId)        

 $levelOne['text'][] = $node->projectName;    

if($node->componentId != $componentId)        

 $levelTwo['text'][] = $node->componentName;    

if($node->workId != $node->workId)        

 $levelThree['text'][] = $node->workName;         

$levelFour['text'][] = $node->revision;    

$levelThree['children'][] = $levelFour;    

$levelTwo['children'][] = $levelThree;    

$levelOne['children'][] = $levelTwo;         

$leveOneId= $node->leveOneId;    

$leveTwoId= $node->leveTwoId;    

$leveThreeId= $node->leveThreeId; 

?> 



As I doesn’t have any support I tried the old way :





<ul id='treeview'>

<?php 

$projectId = 0;$componentId = 0; $workId = 0; $archive = 0;

foreach($nodes as $node): ?>

    <?php if($projectId != $node->projectId): if($archive == 1)echo "</ul>";$archive = 0;$componentId = 0; $workId = 0;?>

    <li><?php echo $node->projectName; ?></li>

    <?php endif; ?>

    <ul>

        <?php if($componentId != $node->componentId): ?>

        <li><?php echo $node->componentName ?></li>

        <?php endif; ?>

        <ul>

            <?php if($workId != $node->workId): ?>

            <li><?php echo $node->workName ?></li>

            <?php endif; ?>

            <?php if($node->status == 2 && $archive == 0){ $archive = 1;echo "<ul><li>Archive</li>";} ?>

            <ul>

                <li><?php echo CHtml::link("(v".$node->revision.") ".$node->statusText,array('view','id'=>$node->id)) ?></li>

            </ul>

        </ul>

        <?php $projectId = $node->projectId; $componentId = $node->componentId; $workId = $node->workId; ?>

    </ul>

<?php endforeach; if($archive == 1)echo "</ul>";?>

</ul>



But still have a bug :

TypeError: settings is undefined

[Break On This Error]

if (!settings.url) {

Thanks for helps