Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在可排序表的数据库中保存新的行顺序_Php_Jquery_Mongodb_Yii2_Jquery Ui Sortable - Fatal编程技术网

Php 在可排序表的数据库中保存新的行顺序

Php 在可排序表的数据库中保存新的行顺序,php,jquery,mongodb,yii2,jquery-ui-sortable,Php,Jquery,Mongodb,Yii2,Jquery Ui Sortable,我已经研究了很多这样的问题,但似乎找不到适合我的解决方案。我在PHP和MongoDB中为我的数据库使用Yi2框架。我还使用了,并且已经使用composer在我的web应用程序中安装了它 这是我的视图中的GridView: <?php echo SortableGridView::widget([ 'dataProvider' => $dataProvider, //'filterModel' => $searchModel, 'columns' =>

我已经研究了很多这样的问题,但似乎找不到适合我的解决方案。我在PHP和MongoDB中为我的数据库使用Yi2框架。我还使用了,并且已经使用composer在我的web应用程序中安装了它

这是我的视图中的GridView

<?php echo SortableGridView::widget([
    'dataProvider' => $dataProvider,
    //'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'code_type',
        'payroll_name',
        'cpf_type',
        [    
            'label' => 'Action',    
            'content' => function ($model, $key, $index, $column) {
                 if ( ($model->company_id != null) && ($model->active == 1) ) {
                    if(in_array($model->payroll_name, array('Basic Salary', 'Overtime Pay', 'Daily/Hourly Wage', 'Commission', 'Bonus', 'Housing Allowance', 'Educational Allowance', 'Travel Allowance', 'Marriage Allowance', 'Leave Encashment', 'Reimbursement'))){
                        return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2']);
                    } else {
                        return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2'])
                        .'&nbsp'
                        . Html::button('<span class="glyphicon glyphicon-pencil"></span>', ['value' => Url::to(['update-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-success btn-view btn-responsive','id' => 'modalButton3'])
                        .'&nbsp'
                        . Html::a('<span class="glyphicon glyphicon-remove"></span>', ['delete-earnings', 'id' => (string)$model->_id], ['class' => 'btn btn-danger btn-responsive', 'data' => ['confirm' => 'Are you sure you want to delete this earnings item?', 'method' => 'post']])
                        .'&nbsp'
                        . Html::button('Unset as Default', ['value' => (string)$model->_id, 'class' => 'btn btn-danger btn-responsive', 'onclick'=>'unset(value)']);
                    }
                } else { 
                    return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2'])
                    .'&nbsp'
                    . Html::button('<span class="glyphicon glyphicon-pencil"></span>', ['value' => Url::to(['update-earnings']).'&id=' . (string)$model->_id, 'class' => 'btn btn-success btn-view btn-responsive','id' => 'modalButton3'])
                    .'&nbsp'
                    . Html::a('<span class="glyphicon glyphicon-remove"></span>', ['delete-earnings', 'id' => (string)$model->_id], ['class' => 'btn btn-danger btn-responsive', 'data' => ['confirm' => 'Are you sure you want to delete this earnings item?', 'method' => 'post']])
                    .'&nbsp'
                    . Html::button('Set as Default', ['value' => (string)$model->_id, 'class' => 'btn btn-info btn-responsive', 'onclick'=>'set(value)']);
                }
            }
        ]
    ],   
    'sortableAction' => Yii::$app->request->baseUrl . '/index.php?r=payroll-items/earnings-index'
]); ?>
控制器:

public function behaviors()
{
    return [
        'sort' => [
            'class' => SortableGridBehavior::className(),
            'sortableAttribute' => 'sortOrder'
        ],
    ];
}
public function actions()
{
    return [
        'sort' => [
            'class' => SortableGridAction::className(),
            'modelName' => PayrollItems::className(),
        ],
    ];
}
我发现了这个,但我不知道在
updateworkshops.php
(见顶部答案)中放什么,因为我使用的是MongoDB而不是MySQL

与我当前的进度一样,我只能拖动GridView行,但新的顺序仍然无法保存在数据库中


有人能给我解释一下怎么做吗?

使用事务性数据库似乎很难编码,您可以随时扩展
SortableGridBehavior
,实现您自己的
gridSort
beforeInsert
方法来正确使用MongoDB。