O
O
Oversec2016-09-22 10:17:23
Yii
Oversec, 2016-09-22 10:17:23

How to pass back the id of the selected user from the modal window to the view?

I have such a task. In the GridView where you can select multiple applications using the checkbox, you need to make a button, when clicked, a modal window will open and there will be a list of drivers in the GridView, where the "Select" button will be. After selecting a driver, you need to pass his id back to the original view and assign it to requests. I made a modal window with a list of drivers, but I can’t figure out how to pass the id of the selected records there.
I thought to pass parameters through ajax, but then I don’t know how to implement it in a modal window.
Maybe someone can help?

<?php Modal::begin([
                    'header' => 'Установить водителя',
                    'size' => 'modal-lg',
                    'toggleButton' => [
                        'tag' => 'a',
                        'class' => 'btn btn-primary',
                        'label' => 'Установить водителя',
                    ]
                ]);

              echo $this->render('_setDriver');

                Modal::end(); ?>

_setDriver.php
<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            [
                'attribute' => 'id',
                'value' => function ($modal) {
                    return '#'. $modal->id;
                },
            ],
            'name',
            'car',
            'gov',
            'rights',
            [
                'attribute' => 'id',
                'label' => 'Выбрать водителя',
                'format' => 'html',
                'filter' => false,
                'value' => function ($model) {
                    $value = '<a href="driverChoose?id='.$model->id.'" class="btn btn-danger">Выбрать</a>';
                    return $value;
                }
            ]
        ],
    ]); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-09-22
@Oversec

With js. The modal window is not another page.
You can send a request to the controller with a parameter and reload the page, yes, there are a lot of options, but you didn’t describe enough to go to the specifics

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question