How to create a Widget - Recent Comments widget

Here's a simple way to create a Recent comments showing widget to be used in your templates. The idea is just to highlighting your blog's new comments.

Step 1: - Creating a Widget Component



class Comments extends CPortlet
	public $title='Recent Comments';
	public $maxComments=10;

	public function getComments()
		return Comment::model()->findRecentComments($this->maxComments);

	protected function renderContent()

step 2 :- in components/views/comments.php

here comes the view file ('comments')

$comments = $this->getComments();

foreach($comments as $comment)
	echo "<li> {$comment->fieldName}</li>";

Step 3 :- in model model/Comment.php

public function findRecentComments($limit=null)
		return $this->findAll(array(
			'order'=>'t.create_time DESC',

Final step, Step 4 :- In your layout


$this->widget('Comments', array(

Happy Coding Yes It Is ........