embed menu from external file

hi there,

i wanna ask, i have problem to embed menu from external file




/protected/modules/site/components/Menu.php

return array(

				array('label'=>'Home', 'url'=>array('/site/index')),

				array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),

				array('label'=>'Contact', 'url'=>array('/site/contact')),

				array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),

				array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)

			);



i wanna call this file into CMenu widget on current themes. Can anybody tell me how to do that. Thx

It’s easier to put your menu file in one location with your theme, then just include it


	

<div id="mainmenu"> 		

<?php include('Menu.php'); ?> 	

</div><!-- mainmenu -->

thx for reply itmagetan,

if i use ur technique, its work. But i wanna little use oop technique, so change the Menu.php




class Menu {

    public function  getList() {

        return array(

            array('label'=>'Home', 'url'=>array('/site/index')),

            array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),

            array('label'=>'Contact', 'url'=>array('/site/contact')),

            array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),

            array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)

	);

   }

}



on modules/site/SiteModule.php, i modify




class SiteModule extends CWebModule

{

    public $navmenu;

public function init()

	{

		// this method is called when the module is being created

		// you may place code here to customize the module or the application


		// import the module-level models and components

		$this->setImport(array(

			'Site.models.*',

			'Site.components.*',

		));

	

                

        }


public function beforeControllerAction($controller, $action)

	{

		if(parent::beforeControllerAction($controller, $action))

		{

			// this method is called before any module controller action is performed

			// you may place customized code here

                        /*print_r(Yii::import('kio'));


                    exit;*/

                 $_menu = new Menu;

                 //print_r($menu->getList());exit;

                 $this->navmenu = $_menu->getList();

                 //print_r($this->menu);

			return true;

		}

		else

			return false;

	}

}



in current theme i call menu function




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

			'items'=>  $this->navmenu,

		)); ?>

its return nothing, but i took a test call this variable on sitemodule, and it work.

the problem just came when call in current theme (the value of $this->menu returns nothing). can anyone want to help me

Have you already put this line in your main.php file?




	// autoloading model and component classes

	'import'=>array(

                ...

		'application.modules.site.components.*',

		...

	),



i have followed your instruction but still not work, the value is still empty. I have added a complete code of siteModule (on my code above at reply no 2). I still confused about this. o yea, did i put those code in wrong place?

and in init function? Maybe it should be like this (i don’t know if it will work or not):




public function init()

        {

                // this method is called when the module is being created

                // you may place code here to customize the module or the application


                // import the module-level models and components

                $this->setImport(array(

                        'Site.models.*',

                        'Site.components.*',

                        'application.modules.site.components.*',

                ));

        

                

        }



thx for replay again :)

yeah i knew the problem. the variable is not set into defaultController of current module.

after I moved that code into controller, menu is generated successfully. But every controller of current module must has this code. Can we write this code in that siteModule and call in controller, in order not to write much code :P