This article is tagged because it NEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.
void move ($dirn, [$where = ])
|$dirn||integer||Direction to move the record. $dirn < 0 for up, $dirn > 0 for down.|
|$where||string||Additional where query to limit ordering to a particular subset of records|
Your database table must have a column named 'ordering'.
What does the method do?
The goal of the method is to move a record of the table one step up, or one step down by switching the ordering values with the respective neighbour.
Let's say we have the following database-table:
We now want to move down the entry 'Hello' one step.
//We need an instance of the table object. In a controller or model we can do it like this... $table = $this->getTable('greeting'); //We need to load the 'Hello' entry into the table object. The id (which is the primary key of the table) of this entry is 1. $table->load(1); //We now want to move the 'Hello' entry one step down. That means, the $dirn Parameter must be positive. //We choose the value 1, but it could also be any other positive number $table->move(1);
The first thing the method does is to load the record which has the next higher ordering value. (If our $dirn paremeter would have been negative, it would have loaded the record with the next lower ordering value. In our case, this is the record with the id #4.
The next (and last step) is that the method switches the ordering values of both records.
In the end the table looks like this: