C:\wamp\www\yii2\vendor\yiisoft\yii2\widgets
klasöründe yeni bir HelloWidget.php
dosyası açılır.
namespace yii\widgets;
use yii\base\Widget;
use yii\helpers\Html;
class HelloWidget extends Widget
{
public $message;
public function init()
{
parent::init();
if ($this->message === null) {
$this->message = 'Hello World';
}
}
public function run()
{
return Html::encode($this->message);
}
}
view.php
dosyasında kullanımı ise
use yii\widgets\HelloWidget;
echo HelloWidget::widget(['message' => 'Good morning'])
init() - should contain the widget properties,run() - should contain rendering result of the widget