Maslosoft Framework Documentation
Flexible Application Foundation
Grid Fields
Grid fields form renderer will display editable grid with fields of nested model selected by annotation. Any form renderer could be used on nested model.
Example form with multiple models. This form also features other fields.
Code used to create this form (and initialize model) is pretty simple:
$model = new ExampleGridFieldsRenderer; $model->items = [ new ExampleGridFieldsItem, new ExampleGridFieldsItem ]; $form = ActiveForm::widget([ 'model' => $model ]); echo $form->renderFields('name', 'items', 'description');
Crucial part is definition of field items
of class ExampleGridFieldsRenderer
is
FormRendererAnnotation
annotation - @FormRenderer
.
First parameter is class literal for GridFields
, second is fields used to render inputs,
third parameter disables confirmation window:
/** * @Label('Items to achieve') * @EmbeddedArray(ExampleGridFieldsItem) * @Renderer(GridFields, {'title', 'proportions', 'active'}, false) * @see GridFields * @var ExampleGridFieldsItem[] */ public $items;There is also named parameter
sortable
to control whether field should be sortable.
Params can be also written in expanded form:
/** * @Label('Items to achieve') * @EmbeddedArray(ExampleGridFieldsItem) * @Renderer(GridFields, {'title', 'active'}, confirm = false, sortable = false) * @see GridFields * @var ExampleGridFieldsItem[] */ public $items;
Example form with disabled sortable, configured as in snippet above.
Code used to create above form. Name and description fields are skipped here:
$model = new ExampleGridFieldsRendererExpandedNotation; $model->items = [ new ExampleGridFieldsItem, new ExampleGridFieldsItem ]; $form = ActiveForm::widget([ 'model' => $model ]); echo $form->renderFields('items');