Custom Widget in Yii
I create new widget like this:
class MyMenu extends CWidget
{
public function init()
{
}
public function run()
{
$Items = array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'Add User', 'url'=>array('/user/register')),
array('label'=>'View Users', 'url'=>array('/user/index')),
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)
);
$this->render('MyMenu', array('Items'=>$Items));
}
}
and view for this widget
echo '<div id="Menu">';
$this->widget('zii.widgets.CMenu',array(
'items' => $Items,
));
echo '</div>';
This is paths of my widget files:
But i get error
MyMenu Widget can not find the view "MyMenu"
What i made wrong?
You should call the directory views
instead of view
.
Source code shows it: http://www.yiiframework.com/doc/api/1.1/CWidget#getViewPath-detail
链接地址: http://www.djcxy.com/p/69734.html上一篇: Yii小部件不工作
下一篇: Yii中的自定义小部件