如何在Yii中制作小部件
我想创建一个小部件,下面是我所做的步骤:
protected文件夹中创建文件夹widgets widgets创建文件夹views 。 config/main.php添加了这个: 'application.widgets.*' widgets/Alert.php的代码: class AlertWidget extends CWidget
{
    public $alert = null;
    private $_data = null;
    public function init()
    {
        $s = Yii::app()->session['userId'];
        $r = Requests::model()->findAll('idUser='.$s.' and confirm =0 and unconfirm=0 and cancel=0');
        $i=0;
        foreach($r as $x)
            $i++;
            if($i<=0)
                $alert=null;
            else
                $alert="(".$i.")";
        $this->_data = new CActiveDataProvider($alert);
    }
    public function run()
    {
        $this->render('alert', ['data' => $this->_data]);
    }
}
widgets/views/alert.php的代码: echo $data;
$this->widget('application.widgets.Alert');
最后我得到了这些错误:
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Cannot redeclare class AlertWidget in C:wampwwwmediastoreprotectedwidgetsAlert.php on line 27
  如果你打算使用$this->widget('application.widgets.Alert');访问widget $this->widget('application.widgets.Alert');  那么,小部件的类名应该是Alert (例如: public class Alert extends CWidget... ),并且文件名应该保持为Alert.php 
上一篇: how to make widget in Yii
下一篇: yii bootstrap + widget TbButtonColumn + widget TbButtonGroup
