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

时间:2015-07-29 07:46:59

标签: php jquery mongodb yii2 jquery-ui-sortable

我研究了很多这样的问题,但我似乎无法为我找到合适的解决方案。我在PHP nad MongoDB中使用Yii2框架作为我的数据库。我也在使用Yii2 sortable extension for GridView并已使用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(),
        ],
    ];
}

我发现了这个problem,但我不知道在updateworkshops.php内放什么(参见最佳答案),因为我使用的是MongoDB,而不是MySQL。

在我当前的进度中,我只能拖动我的GridView行,但新订单仍然无法保存在我的数据库中。

有人可以向我解释如何做到这一点吗?

0 个答案:

没有答案
相关问题