如果我理解正確的話,以上是編輯好,但不適用於添加。該解決方案應爲這兩種情況下工作:
在您的控制器或你的/app/app_controller.php,放像這樣添加:
$insertID = $this->{$this->modelClass}->getLastInsertID();
$page = $this->{$this->modelClass}->getPageNumber($insertID, $this->paginate['limit']);
$this->redirect("/admin/{$controllerName}/index/page:{$page}");
...而像這樣編輯:
$page = $this->{$this->modelClass}->getPageNumber($id, $this->paginate['limit']);
$this->redirect("/admin/{$controllerName}/index/page:{$page}");
在你/app/app_model.php,把這個:
/**
* Work out which page a record is on, so the user can be redirected to
* the correct page. (Not necessarily the page she came from, as this
* could be a new record.)
*/
function getPageNumber($id, $rowsPerPage) {
$result = $this->find('list'); // id => name
$resultIDs = array_keys($result); // position - 1 => id
$resultPositions = array_flip($resultIDs); // id => position - 1
$position = $resultPositions[$id] + 1; // Find the row number of the record
$page = ceil($position/$rowsPerPage); // Find the page of that row number
return $page;
}
希望幫助!
一些代碼將是有益的。您可能必須將頁碼放在「編輯」鏈接中。 – slosd 2009-06-28 20:24:33