在Yii Framework中创建一个新的Widget

时间:2014-12-04 07:37:13

标签: php yii yii-components yii-widgets

我在项目上创建了一个Yii小部件,虽然我正确地遵循了所有的命名约定,但我遇到了一个问题。

出错了

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

我已正确地在 main.php 中添加了路径application.components.*,但我不知道它为什么没有检测到。

recentCommentsWidget.php 保存在组件目录中的视图目录中。

有什么遗失的吗?

编辑:这是RecentCommentsWidget类(路径=> 应用程序/组件

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文件(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>

这就是我称之为观点

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

已解决:我写了 recentComments.php 而不是 recentCommentsWidget.php

0 个答案:

没有答案
相关问题