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;
}
}
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.*',
));
}
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