D
D
Denis Rybin2015-10-22 04:12:47
Yii
Denis Rybin, 2015-10-22 04:12:47

How to change the id of two adjacent records in yii2?

Hello, the situation is this: you need to make a function to change the order of displaying records in the list. those. the ability to raise and lower the record by one order.
I made a sort column in the table, in which the id of the record is written when it is created.
The list is displayed sorted by the sort field.
For example, let's take a record with id=5,
then we need to calculate the neighboring nearest records and swap their data in the sort column.
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Khomenko, 2015-10-22
@RybinDen

Use ready-made solutions. They did it for you a long time ago, and very well.
https://github.com/yii2tech/ar-position The extension was written by Klimov, one of the main Yii2 maintainers.
Try to study the extension and understand how everything works there. If anything - write, I'll tell you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question