CMenu and 'items' property

Here is the code I am using to call CMenu:


<?php

$this->widget('zii.widgets.CMenu',array(

  'activeCssClass'=>'active',

  'activateParents'=>true,

  'items'=>Category::getMenuItems(),

));

 ?>

However, I get an error:


PHP warning


Invalid argument supplied for foreach() 


/www/yii/framework/zii/widgets/CMenu.php(255)


253     protected function normalizeItems($items,$route,&$active)

254     {

255         foreach($items as $i=>$item)

256         {

257             if(isset($item['visible']) && !$item['visible'])

258             {

259                 unset($items[$i]);

260                 continue;

261             }

262             if(!isset($item['label']))

263                 $item['label']='';

264             if($this->encodeLabel)

265                 $items[$i]['label']=CHtml::encode($item['label']);

266             $hasActiveChild=false;

267             if(isset($item['items']))



Category::getMenuItems() is a recursive function that returns an array:


Array

(

    [label] => All Categories

    [url] => Array

        (

            [0] => auction/index

            [category] => All Categories

        )


    [items] => Array

        (

            [0] => Array

                (

                    [label] => Jewelry

                    [url] => Array

                        (

                            [0] => auction/index

                            [category] => Jewelry

                        )


                    [items] => Array

                        (

                            [0] => Array

                                (

                                    [label] => Watches

                                    [url] => Array

                                        (

                                            [0] => auction/index

                                            [category] => Watches

                                        )


                                )


                            [1] => Array

                                (

                                    [label] => Rings

                                    [url] => Array

                                        (

                                            [0] => auction/index

                                            [category] => Rings

                                        )


                                    [items] => Array

                                        (

                                            [0] => Array

                                                (

                                                    [label] => Engagement

                                                    [url] => Array

                                                        (

                                                            [0] => auction/index

                                                            [category] => Engagement

                                                        )


                                                    [items] => Array

                                                        (

                                                            [0] => Array

                                                                (

                                                                    [label] => Gold

                                                                    [url] => Array

                                                                        (

                                                                            [0] => auction/index

                                                                            [category] => Gold

                                                                        )


                                                                )


                                                        )


                                                )


                                        )


                                )


                        )


                )


            [1] => Array

                (

                    [label] => Motorcycles

                    [url] => Array

                        (

                            [0] => auction/index

                            [category] => Motorcycles

                        )


                    [items] => Array

                        (

                            [0] => Array

                                (

                                    [label] => Harley Davidson

                                    [url] => Array

                                        (

                                            [0] => auction/index

                                            [category] => Harley Davidson

                                        )


                                )


                            [1] => Array

                                (

                                    [label] => Ducati

                                    [url] => Array

                                        (

                                            [0] => auction/index

                                            [category] => Ducati

                                        )


                                )


                        )


                )


            [2] => Array

                (

                    [label] => Toys

                    [url] => Array

                        (

                            [0] => auction/index

                            [category] => Toys

                        )


                )


            [3] => Array

                (

                    [label] => Electronics

                    [url] => Array

                        (

                            [0] => auction/index

                            [category] => Electronics

                        )


                    [items] => Array

                        (

                            [0] => Array

                                (

                                    [label] => Video Games

                                    [url] => Array

                                        (

                                            [0] => auction/index

                                            [category] => Video Games

                                        )


                                )


                            [1] => Array

                                (

                                    [label] => Watches

                                    [url] => Array

                                        (

                                            [0] => auction/index

                                            [category] => Watches

                                        )


                                )


                        )


                )


        )


)

items should be an array of arrays… so you need one array as holder of the Category::getMenuItems() result…

Awesome, works now, thanks.