문제

How to import Yii Controller in Yii widgets;

My Widget code is:

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

}

Now I call my component/controller function $this->getAuthor($blog->author_id) in this widget view but giving me error:

RecentBlogsWidget and its behaviors do not have a method or closure named "getAuthor".

도움이 되었습니까?

해결책

I just imported my Controller in my

  views/RecentBlogsWidget.php     
  Yii::import('application.components.Controller'); 

and then call my method like this:

  Controller::getAuthor($blog->author_id);

it is working now for me.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top