how to make widget in Yii
I want to create a widget, here is the steps I made:
widgets in folder protected .  views in folder widgets .  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');
finally I got these errors:
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Cannot redeclare class AlertWidget in C:wampwwwmediastoreprotectedwidgetsAlert.php on line 27
 if you're going to access the widget using $this->widget('application.widgets.Alert');  then, the widget class name should be Alert (like: public class Alert extends CWidget... ) and the filename should remain Alert.php  
上一篇: JQuery添加/删除类不工作的第二次
下一篇: 如何在Yii中制作小部件
