views:

18

answers:

1

one more question related with cakephp...

let's say that i have 20+ records in my table. they are sorted by some criteria, ie. by title. and on a list view, i have a list of 10 records, with available pagination.

how can i achieve that when i insert new record, to be redirected to proper page, where i can see record that is just was insterted? how can i get information on which page i have to be redirected?

hope my question is enough clear for understanding...

tnx in adv!

A: 

I do not think you can do it in CakePHP without unnecessary database queries if you do not sort your records by id. You can get the id of the last saved record this way: $this->YourModel->save($data); $newId = $this->YourModel->id; You can use this id to redirect to $this->redirect(array('action' => 'view', $newId)); to ensure the record has been saved.

Or after saving the new record you can redirect to /your_model/index/page:1/sort:id/direction:desc.

bancer
If the inserted row is going to be the first one by the ordering, the solution is trivial - just redirect to the first/last page. But I guess that's not the case. How do you know the page number of a particular ID when the sort order is not ID?
sibidiba
You must sort by ID: `/your_model/index/page:1/sort:id/direction:desc`. Is there any sense to sort another way if you want to check if the record has been added? Would you look for the new record somewhere in the middle of the list? Is it convenient?
bancer