diff --git a/docs/guide-ja/structure-widgets.md b/docs/guide-ja/structure-widgets.md new file mode 100644 index 0000000000..4d8f737f85 --- /dev/null +++ b/docs/guide-ja/structure-widgets.md @@ -0,0 +1,192 @@ +Widgets +======= + +Widgets are reusable building blocks used in [views](structure-views.md) to create complex and configurable user +interface elements in an object-oriented fashion. For example, a date picker widget may generate a fancy date picker +that allows users to pick a date as their input. All you need to do is just to insert the code in a view +like the following: + +```php + += DatePicker::widget(['name' => 'date']) ?> +``` + +There are a good number of widgets bundled with Yii, such as [[yii\widgets\ActiveForm|active form]], +[[yii\widgets\Menu|menu]], [jQuery UI widgets](widget-jui.md), [Twitter Bootstrap widgets](widget-bootstrap.md). +In the following, we will introduce the basic knowledge about widgets. Please refer to the class API documentation +if you want to learn about the usage of a particular widget. + + +## Using Widgets + +Widgets are primarily used in [views](structure-views.md). You can call the [[yii\base\Widget::widget()]] method +to use a widget in a view. The method takes a [configuration](concept-configurations.md) array for initializing +the widget and returns the rendering result of the widget. For example, the following code inserts a date picker +widget which is configured to use Russian language and keep the input in the `from_date` attribute of `$model`. + +```php + += DatePicker::widget([ + 'model' => $model, + 'attribute' => 'from_date', + 'language' => 'ru', + 'clientOptions' => [ + 'dateFormat' => 'yy-mm-dd', + ], +]) ?> +``` + +Some widgets can take a block of content which should be enclosed between the invocation of +[[yii\base\Widget::begin()]] and [[yii\base\Widget::end()]]. For example, the following code uses the +[[yii\widgets\ActiveForm]] widget to generate a login form. The widget will generate the opening and closing +`