문제

항목을 나열하는 인덱스 뷰가 있으며 긴 목록이므로 Paginator를 사용하여 항목을 50 대의 뷰로 제한합니다.

각 항목에는 입력/유효성 검사 등이있는 편집보기로 이동하는 "편집"링크가 있습니다. 해당 양식이 제출되면 사용을 색인보기로 다시 리디렉션합니다.

지금까지 너무 좋지만 여기에 문지름이 있습니다.

사용자가 색인 N 페이지에 있고 항목 편집을 클릭하고 편집하는 경우 색인 N 페이지로 다시 리디렉션되기를 원합니다. 페이지 번호를 알고 있다면 URL의 끝까지 "/page : n"을 붙일 수는 있지만 페이지 번호를 얻을 수있는 방법은 모르겠습니다. (n 페이지 번호가 될 수 있지만 특히> = 2)

모든 아이디어는 감사 할 것입니다.

도움이 되었습니까?

해결책

페이지 번호는 목록보기에서 $ params var의 일부 여야합니다. 편집 링크의 끝에 문제를 해결하고 거기에서 처리하십시오. 편집 페이지에서 옵션 페이지 번호를 사용하여 양식 제출 중에 저장하고 동일한 페이지 번호로 목록으로 다시 전달할 수있는 방법이 필요합니다.

다른 팁

세션에서 페이지를 저장하는 구성 요소를 만들었습니다. 그런 다음 app_controller.php에서 사용중인 특정 모델에 대한 세션에 어떤 것이 있는지 확인한 다음 URL에 추가합니다. 구성 요소 코드에 관심이 있으시면 메시지를 보내주십시오. 사용자가 편집하기 전에 인덱스 페이지에서 정렬 순서를 변경 한 경우 주문을 저장합니다.

소스는 여기를 참조하십시오.http://github.com/jimiyash/cake-pluggables/blob/a0c3774982c19d02cfdd19a2977abe046a4b294/controllers/components/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