V
V
VitaliyKaliuzhyn2017-03-10 11:19:46
Yii
VitaliyKaliuzhyn, 2017-03-10 11:19:46

Conditions for outputting input?

There is a table that is formed like this

<?php Pjax::begin(); ?>
    <?= GridView::widget([
        'filterUrl' => Yii::$app->map->getByAlias('/mig.modules.admin.modules.users/list')->getUrl(),
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'id',
            'group.name',
            'title',
            'name',
            'value',
            'typeof',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
    <?php Pjax::end(); ?>

she concludes
<tr data-key="4"><td>1</td><td>4</td><td>Регистрация</td><td>Требовать капчу?</td><td>isRequireCaptcha</td><td>5</td><td>boolean</td><td><a href="" title="View" aria-label="View" data-pjax="0"><span class="glyphicon glyphicon-eye-open"></span></a> <a href="" title="Update" aria-label="Update" data-pjax="0"><span class="glyphicon glyphicon-pencil"></span></a> <a href="" title="Delete" aria-label="Delete" data-confirm="Are you sure you want to delete this item?" data-method="post" data-pjax="0"><span class="glyphicon glyphicon-trash"></span></a></td></tr>

When you click on edit, we get into the view, in which the field should be displayed depending on the type of data. In this example, the boolean data type means the view should display the radiolist, if the type of the edited field is a string, then the field should be an ordinary input
, here is the view code itself
<?php $form = ActiveForm::begin(['fieldClass' => 'mig\themes\metronic\admin\widgets\ActiveField', 'options' => ['class' => 'form-horizontal']]); ?>

    <?= $form->field($model, 'value', ['labelOptions' => ['class' => 'col-md-1 control-label']])->textInput(['maxlength' => true, 'class' => 'col-md-3']) ?>
    
    <div class="form-group">
        <?= Html::submitButton(Yii::t('app', 'Сохранить'), ['class' => 'btn btn-primary']) ?>
    </div>
    <?php ActiveForm::end(); ?>

Tell me how this can be implemented within a single view

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Timofeev, 2017-03-10
@VitaliyKaliuzhyn

Option two. Or make a linked table or tables in which to store it. Or store as json in one cell, store data and field type. Depending on the type, display a dropdown or an input or some kind of widget. In the case of json, it will be impossible to sort or search by this cell, but it will be easier to implement.

V
VitaliyKaliuzhyn, 2017-03-10
@VitaliyKaliuzhyn

In fact, there is a table with a typeof field in which the type of the field is indicated, the question is how to display this or that field in the view based on this field

M
mShpakov, 2017-12-12
@mShpakov

nisnom.com/category/web-razrabotki/menyu

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question