Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,36 @@ public function actions()
}
```

If you're using another order field not 'order' (example 'sortingFieldName'), you must specify it in 'orderAttribute' parameter:

```php
public function actions()
{
return [
'sorting' => [
'class' => \kotchuprik\sortable\actions\Sorting::className(),
'query' => \vendor\namespace\Model::find(),
'orderAttribute' => 'sortingFieldName',
],
];
}
```

If you're need start ordering not 0 you must specify it in 'startOrder' parameter:

```php
public function actions()
{
return [
'sorting' => [
'class' => \kotchuprik\sortable\actions\Sorting::className(),
'query' => \vendor\namespace\Model::find(),
'startOrder' => 1
],
];
}
```

If you're using another primary key (not 'id'), you must specify it in 'pk' parameter:

```php
Expand Down
7 changes: 5 additions & 2 deletions actions/Sorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class Sorting extends Action

/** @var string */
public $pk = 'id';


/** @var int */
public $startOrder = 0;

public function run()
{
$transaction = \Yii::$app->db->beginTransaction();
Expand All @@ -28,7 +31,7 @@ public function run()
if ($model === null) {
throw new BadRequestHttpException();
}
$model->{$this->orderAttribute} = $offset + $order;
$model->{$this->orderAttribute} = $offset + $order + $this->startOrder;
$model->update(false, [$this->orderAttribute]);
}
$transaction->commit();
Expand Down