CakePHP Ajax搜索:为分页显示相同的数据两次
这里ajax搜索工作正常,但问题是相同的数据显示了两次,因为我给了分页限制2。如果我给它3,相同的结果显示了3次 这是我的index.ctpCakePHP Ajax搜索:为分页显示相同的数据两次,cakephp,cakephp-2.4,Cakephp,Cakephp 2.4,这里ajax搜索工作正常,但问题是相同的数据显示了两次,因为我给了分页限制2。如果我给它3,相同的结果显示了3次 这是我的index.ctp $( "#search" ).keyup(function() { var value=$('#search').val(); $.get("<?php echo Router::url(array('controller'=>'userTypes','action'=>'search'));?>
$( "#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
<?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 } ?>
结果是这样的
有谁能帮我解决这个问题吗?如果您想使用分页,您的搜索方法应该如下所示:
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());
}
parent::beforeFilter();
$this->Paginator->settings = array(
'limit'=>2
);
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());
}