Widgets
Widgets are reusable units used in views, using object-oriented way to create complex and configurable user interface elements. (Recommended learning: yii framework)
For example, the date picker widget can generate an exquisite date picker that allows users to select dates. You only need to insert the following code in the view:
<?php use yii\jui\DatePicker; ?> <?= DatePicker::widget(['name' => 'date']) ?>
Yii provides many excellent widgets, such as active form, menu, jQuery UI widgets, and Twitter Bootstrap widgets. Next, we will introduce the basic knowledge of widgets. If you want to know about a certain widget, please refer to the corresponding class API document.
Using widgets
Widgets are basically used in views. The yii\base\Widget::widget() method can be called in the view to use widgets. This method initializes the widget using the configuration array and returns the result of the widget being rendered.
For example, the following code inserts a date picker widget, which is configured to use Russian, and the input box content is the from_date attribute value of $model.
<?php use yii\jui\DatePicker; ?> <?= DatePicker::widget([ 'model' => $model, 'attribute' => 'from_date', 'language' => 'ru', 'dateFormat' => 'php:Y-m-d', ]) ?>
Some widgets can use data content in yii\base\Widget::begin() and yii\base\Widget::end() calls.
For example, the following code uses the yii\widgets\ActiveForm widget to generate a login form. The widget will generate the start tag and end tag of