2014-11-02 12 views
0

아약스 검색은 정상적으로 작동하지만 동일한 데이터가 두 번 표시됩니다. 페이지 매김 제한을 2로 지정했기 때문에 3, 동일한 결과가 3 번 표시됩니다. . 여기 CakePHP Ajax 검색 : 페이지 매김에 대해 동일한 데이터를 두 번 표시합니다.

여기 내 검색 작업을

public function search() 
    { 
     $search=$_GET['search']; 
     $request=$this->UserType->find('all', array(
     'conditions' => array('UserType.name LIKE' => "%$search%") 
     )); 
     $this->set('usertype',$request); 
    } 

내 index.ctp 여기

$("#search").keyup(function() { 

    var value=$('#search').val(); 

     $.get("<?php echo Router::url(array('controller'=>'userTypes','action'=>'search'));?>",{search:value},function(data){ 
     $('.search_data').html(data); 
    }); 
}) 

되어있는 search.ctp에게 AppController가

parent::beforeFilter(); 
      $this->Paginator->settings = array(
       'limit'=>2 
     ); 
에서

<?php foreach($usertype as $usertypes) { ?> 
    <tr> 
      <td><?php echo $usertypes['UserType']['id']; ?></td> 
      <td><?php echo $usertypes['UserType']['name']; ?></td> 
      <td><?php echo $usertypes['UserType']['description']; ?></td> 

    </tr> 
<?php } ?> 

매김 제한입니다

결과는 그것을 해결하기 위해 나를 도와이

enter image description here

월 사람처럼 저를 보여주고있다? 당신은 페이지 매김을 사용하려면

답변

1

, 검색 방법은 다음과 같아야합니다

public function search() 
{ 
    if(isset($this->request->query['search'])){ 
     $search = $this->request->query['search']; 
    }else{ 
     $search = ''; 
    ) 
    $this->Paginator->settings = array(
     'conditions' => array('UserType.name LIKE' => "%$search%"), 
     'limit' => 2 
    ); 
    )); 
    $this->set('usertype',$this->Paginator->paginate()); 
}