Monday, March 26, 2018

How to create custom widget in Yii2

Create custom widget in Yii2


In this example We am creating a dropdown widget. This is only provide a basic structure of how to create your own custom widget.


Following files you need to create for widget.

1. _template.php
        print_r($model);
        die;

2.GridviewDropdown.php
namespace common\widgets\dropdownWidget;
use yii\base\Widget;
public function init(){
    parent::init(); } public function run(){     return $this->render('_template', ['items' => $this->data]);
   }
}
3.viewFile.php
echo \common\widgets\dropdownWidget\GridviewDropdown::widget([
            'model' => $model
    ])


1 comment:

  1. It is nice post and I found some interesting information on this blog, keep it up. Thanks for sharing. Dedicated Yii Framework Developers in India

    ReplyDelete

Recent Update

yii2 session handling

use yii\web\Session; $session = Yii::$app->session; // start session $session->open(); // close session $session->close(); ...

Most Search