Creating a new Widget in Yii Framework

892 views Asked by At

I'm creating a Yii widget on a project and I've run into a problem, albeit following all the naming conventions correctly.

Got an error

include(RecentCommentsWidget.php): failed to open stream: No such file or directory

I have included the path application.components.* on main.php correctly but I don't know why it is not detecting.

The recentCommentsWidget.php is saved in a views directory inside the components directory.

Is there anything am missing?

EDIT: Here is the RecentCommentsWidget class ( path => application/components)

class RecentCommentsWidget extends CWidget
{
private $_comments;
public $displayLimit = 5;
public $projectId = null;

public function init()
{
    if(null !== $this->projectId)
        $this->_comments = Comment::model()->with(array(
            'issue'=>array('condition'=>'project_id='.$this->projectId)))->recent($this->displayLimit)->findAll();
    else
        $this->_comments = Comment::model()->recent($this->displayLimit)->findAll();
}

public function getData()
{
    return $this->_comments;
}

public function run()
{
    // this method is called by CController::endWidget()
    $this->render('recentCommentsWidget');
}
}

recentCommentsWidget file (path => application/components/views)

<ul>
    <?php foreach($this->getData() as $comment): ?>
    <div class="author">
        <?php echo $comment->author->username; ?> added a comment.
    </div>
    <div class="issue">
        <?php echo CHtml::link(CHtml::encode($comment->issue->name),array('issue/view', 'id'=>$comment->issue->id)); ?>
    </div>
    <?php endforeach; ?>
</ul>

and this is how i am calling it the views

<?php $this->widget('RecentCommentsWidget'); ?>

SOLVED: I had wrote recentComments.php instead of recentCommentsWidget.php

0

There are 0 answers