ウィジェットを作成したいのですが、私が行った手順は次のとおりです。
widgetsフォルダにフォルダを作成しましたprotected。viewsフォルダにフォルダを作成しました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');
最後に、これらのエラーが発生しました:
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Cannot redeclare class AlertWidget in C:\wamp\www\mediastore\protected\widgets\Alert.php on line 27