Set current pagination position from model id

Hi!

I would like to build a simple forward-backward scroll pager for model detail pages.

Therefore I have to set the pagination page size to 1. All quickly done with Yii.

But how can I set the current page from the model id? (remember: we are on the model detail page)

retrieving the current row in mysql is clear, here are some examples:

What is the best approach to achieve this with Yii when using a CActiveDataProvider with CdbCriteria?

EDIT:

Example usage: Having a grid view with some sorting and/or filtering. When clicking on detail view, I don’t want to go back, but have an previous/next button to page through items (in the same order that was used before in the gridview)

Maybe add an ordering field, with only positive values, and when you request the model by id, you also get the ordering value, which is the "current page".

Yes, that would definitely work, but there are two downsides from my point of view:

  1. you would have to update this order value on any delete in this table

  2. does not work with any other sorting than one pre-calculated default sorting.

When I have the default case (sorting by ID e.g.) I could use a precoded of before mentionend sql statements to calculate the position. That is not hard. But combining this with criteria filters and sorting is pain.

What do you guys think of putting the last used dataProvider of the gridview into a session. When rendering the gridview I can add the total position to each view item link. When clicking from here onto the detail view, I can reuse the dataprovider (from the session) to render a pagination with page size 1 (and setting the current page to the position that was passed by the view item link).

If the view page is opened directly I would have to fallback to a simple default provider (using ID sorting) and calculate the position with an extra sql query (see first post).