Javascript 将数据传递到yii2中的下一页

Javascript 将数据传递到yii2中的下一页,javascript,model-view-controller,yii2,yii2-advanced-app,Javascript,Model View Controller,Yii2,Yii2 Advanced App,我在Yii2做一个项目 要求是,当用户单击gridview中的一行时,它应该打开一个名为check in的新控制器,并显示该特定行的所有已签入用户 我不知道该如何使用actioncolumn和一个新按钮,还是使用rowopions 无论如何,当我像这样使用rowoptions时 [ 'class' => 'yii\grid\ActionColumn', 'template' => '{index} {view} {upd

我在Yii2做一个项目 要求是,当用户单击gridview中的一行时,它应该打开一个名为check in的新控制器,并显示该特定行的所有已签入用户

我不知道该如何使用
actioncolumn
和一个新按钮,还是使用
rowopions

无论如何,当我像这样使用
rowoptions

        [
            'class' => 'yii\grid\ActionColumn',
            'template' => '{index} {view} {update} {delete} ',
            'buttons' => [

                'index' => function ($url,$model) {

                    return Html::a('<span class="glyphicon glyphicon-user"></span>', $url);

                },
            ]

        ],
它重定向到
签入/索引
页面 但是url没有得到任何
id
其显示
checkin/index/id=undefined

我想将id传递给
checkinSearch
控制器,并且只向用户显示单击行的数据。

您可以尝试此操作。。 例如

这个例子是真实项目的一部分,适合我。
试试看……

如果你没有在js上面注册,那么当你点击
ActionColumn
时,你会重定向到行url而不是
ActionColumn
按钮链接。似乎也有同样的问题。。它在同一页上刷新,并将单击的行数据的id附加到url。。。这就是我为解决问题所做的<代码>'onclick'=>'location.href=“”.Url::to(['checkin/index'])。?id=“+(this.id);”将该代码添加到
rowoptoins
return语句中,它现在解决了问题,但我想使用ActionColumn而不是row。。无论如何谢谢你
<?php
        $this->registerJs("
            $('tbody td').css('cursor', 'pointer');
            $('tbody td').click(function (e) {
                var id = $(this).closest('tr').data('id');
            if (e.target == this)
                location.href = '" . Url::to(['checkin/index' ]) . "?id=' + id;
            });
        ");
    ?>
 <?php
    $this->registerJs("

        $('td').click(function (e) {
            var id = $(this).closest('tr').data('id');
            if(e.target == this)
                location.href = '" . Url::to(['checkin/index']) . "?id=' + id;
        });

    ");
?>
<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'rowOptions' => function ($model, $key, $index, $grid) {
                        return ['id' => $model['student_id'], 'class' => 'action-tr', 'data-link' => urldecode(Url::toRoute(['/student/student-transaction/update', 'id' => $model['student_id']]))];
    },
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],

        [
          'attribute' => 'student_roll_no',
          'value' => 'rel_Stud_Info.student_roll_no',
        ],
        [
          'class' => 'yii\grid\ActionColumn',
          'template' => '{update} {delete}',
          'contentOptions' => ['class'=>'action-td'],       
        ],
    ],
]); ?>
<?php
    $this->registerJs("
    $(document).ready(function(){
        $('.action-tr').on('click', 'td:not(.action-td)', function(){

            //get the link from data attribute
            var the_link = $(this).parent().attr('data-link');

            //do we have a valid link      
            if (the_link == '' || typeof the_link === 'undefined') {
            //do nothing for now
            }
            else {
            //open the page
            window.location = the_link;
            }
        });
    });
"); ?>