2016-10-21 7 views
1

이것은 모든 검색 결과가 foreach 루프에서 오는 컨트롤러 파일이지만 페이지 매김을 시도했지만 ' 그것을하는 방법을 알아낼 수 없습니다.CakePHP 3.x를 사용하여 검색 결과를 페이지 매김하고 템플릿보기 파일에 표시하려고합니다.

<?php 
class SerController extends AppController 
{ 
    public function initialize() 
    { 
     parent::initialize(); 
     $this->loadComponent('Paginator'); 
    } 

    public function index() 
    { 
     $check_string=$this->request->data('check'); 
     $check_break=explode(" ",$check_string); 
     $s1=TableRegistry::get('ser_tab'); 
     foreach($check_break as $check) 
     { 
      $s11=$s1->find('all')->where(['OR' =>['text LIKE' => '%'.$check.'%','name LIKE' => '%'.$check.'%']]); 
      $this->set(array('data' => $s11)); 
     }     
     $this->render('index'); 
    } 
} 
+0

DualController.php

<?php public function initialize() { parent::initialize(); $this->loadComponent('Paginator'); } 

공공 기능 지수() {

$r = TableRegistry::get('d11'); $results = $r->find('all'); $this->set(array('data11' => $results)); $this->Paginator->paginate($results,$settings); $this->set('index'); 

} ** 전체 텍스트 검색 ** HTTP : //www.hackingwithphp .com/9/3/18/advanced-text-searching-full-text-indexes 사용 – tarikul05

+0

페이지 매김 사용하기 http://stackoverflow.com/a/6184178/3278789 – tarikul05

답변

0

쿼리가 실행되는 데 너무 오래 걸립니다. 당신은 간단하게 그것을 할 수 있습니다. 처럼 index() 기능을 업데이트 로

예 아래 [때 URL에서 데이터]

public function index($data='Default text here'){ /*When get Data from the URL*/ 
    $data = explode(' ', $data); 
    $conditions = array(); /*All OR conditions will store here*/ 

    foreach ($data as $key => $value) { 
     $conditions['or'][] = array('text LIKE' => "%$value%"); 
     $conditions['or'][] = array('name LIKE' => "%$value%"); 
    } 

    $this->paginate = [ 
     'limit' => 25, #Set the limit of post 
     'conditions'=>[ 
      $conditions /*OR conditions array*/ 
     ] 
    ]; 

    $data = $this->paginate(); 
    var_dump($conditions,$data);   /*Debug OR Condition array and Query data*/ 
    $this->set(compact('data'));   /*Set the Posts to a variable*/ 
} 

예 [때 POST 데이터]

public function index(){ 
    if ($this->request->is('post')) { 
     $data = $this->request->data('check'); 
     # YOUR CODE HERE 
    } 
} 

CakePHP의 3.x의 페이지 매김 문서 is HERE

+0

또는 PRG를 사용하십시오. [Search] (https://github.com/FriendsOfCake/search) plugin for itered;) 컨트롤러 범위에서 제대로 코드를 작성하지 않고 적절하게 해결했습니다. – mark

+0

모델없이 페이지 매김을 추가 할 수 있으며 컨트롤러와 뷰를 사용하는 것만으로 –

+0

예! Paginator 구성 요소를 직접 사용할 수 있습니다. '$ this-> Paginator-> paginate (YOUR_QUERY_OBJECT, CONFIGS)'와 비슷합니다. 자세한 내용은 다음과 같습니다 (http://book.cakephp.org/3.0/en/controllers/components/pagination.html#using-the-paginator-directly) @HarjeevSingh –

1

데이터 집합 결과의 값을 페이지 매김하려고하는데 컨트롤러의 모든 코드를 작성했지만 오류가 발생하지 않습니다. 제 질문은 VIEW에서 값을 가져 오는 방법입니다. 당신은 MySQL을 사용 할 수 있습니다