如何在Yii小部件中导入Yii Controller;
我的Widget代码是:
class RecentBlogsWidget extends CWidget {
public $showblogs;
public function run() {
Yii::import("application.components.Controller");
$model = Blog::model()->activeBlogsWidget($this->showblogs)->findAll();
$this->render('RecentBlogs',
array(
'model' => $model,
)
);
}
}
现在我在这个小部件视图中调用我的组件/控制器函数$this->getAuthor($blog->author_id)
但是给了我错误:
RecentBlogsWidget and its behaviors do not have a method or closure named "getAuthor".
答案 0 :(得分:0)
我刚刚在我的
中导入了我的控制器 views/RecentBlogsWidget.php
Yii::import('application.components.Controller');
然后调用我的方法:
Controller::getAuthor($blog->author_id);
它现在正在为我工作。