我有,该目录项的索引图,它是一个长列表,以便我使用分页程序项限制在50到一个视图。

每个项目都有一个“编辑”链接前进到与输入/验证/等的编辑视图。当提交表单时,我重定向使用回索引视图。

到目前为止好,但这里的难题是:

如果用户是对指数的页面N和他们点击编辑和编辑项目,我希望他们能够被重定向回索引的N页。如果我知道的页码,我只是坚持“/页:N”到URL的结束,但我不知道我怎样才能得到的页码。 (N可以是任何页号,但尤其是> = 2)

任何想法,将不胜感激。

有帮助吗?

解决方案

在页面数量应在列表视图中的$ PARAMS变种的一部分。只是它钉住到编辑环节的结束,并从那里处理。在编辑页面,您将需要一个方式,采取在任意页面数,任何形式的提交过程中其存储,并转发回用相同的页码的列表。

其他提示

我创建的会话保存的页面的部件。然后在app_controller.php,我检查,看看是否有在特定型号的会话任何使用,然后添加到URL。如果你有兴趣在代码组件,给我发短信。我还存放了订单,如果用户在索引页面编辑前更改了排序顺序。

请参阅此处为源: http://github.com/jimiyash/cake-可插拔/斑点/ a0c3774982c19d02cfdd19a2977eabe046a4b294 /控制器/组件/ memory.php

下面是我在做什么的要点。

//controller or component code
if(!empty($params['named']) && !empty($params['controller']) && $params['action'] == 'admin_index'){
    $this->Session->write("Pagem.{$params['controller']}", $params['named']);
}

//app_controller.php
    $redirectNew = "";
    if(is_array($redirectTo)){
        if(!empty($params['prefix']) && $params['prefix'] == 'admin'){
            $redirectNew .= '/admin';
        }
        if(!empty($params['controller'])){
            $redirectNew .= "/" . $params['controller'];
        }
        if(!empty($redirectTo['action'])){
            $redirectNew .= "/" . $redirectTo['action'];
        }
    } else {
        $redirectNew = $redirectTo;
    }

    $controller = $params['controller'];
    if($this->Session->check("Pagem.$controller")){
        $settings =  $this->Session->read("Pagem.$controller");
        $append = array();
        foreach($settings as $key=>$value){
            $append[] = "$key:$value";
        }
        return $redirectNew . "/" . join("/", $append);
    } else {
        return $redirectNew;
    }

如果正确地明白上面是细进行编辑,但不添加。该溶液还应当对于这两种情况下工作:

在你的控制器或者/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;
  }

希望帮助!

执行一个简单的

$this->redirect($this->referer());

作品?

在考虑到与分页程序:

<?php
if ($this->Paginator->hasPage(null, 2)) {   
$pag_Start = $this->Paginator->counter('{:start}');
$pag_End = $this->Paginator->counter('{:end}');
if( $pag_Start == $pag_End ){
$pageToRedirect = $this->Paginator->current('Posts');
}else{
$pageToRedirect= '';
}}?>

然后链接到编辑页面

<?php
echo $this->Form->postLink(
'Edit',
array('action' => 'edit', $subscription['Post']['id']));
?>

在控制器:

public function edit($post_id, $pageToRedirect = false){

    //after all editing its done redirect

    if($pageToRedirect){
    // if record was last in pagination page redirect to previous page
    $pageToRedirect = $pageToRedirect -1;
    return $this->redirect(array('action' => 'index/page:'.$pageToRedirect ));
    }else{
    // else redirect to the same pagination page
    $this->redirect($this->referer());          
    }

}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top