我正在为分页而苦苦挣扎。 我想使用默认功能。 问题是,分页按钮(数字,上一页,下一页)的链接不起作用。 我不知道如何将URL中的“page:2”传递给paginator,让他知道他必须显示/呈现下一个5结果的表格。 例如:我点击页面2上的“2”,网站将被刷新,但根本没有显示结果表。CakePHP分页显示结果问题
其他信息: 输入字段的URL位于cakephp/Posts/index。当我点击一个分页按钮(例如prev)时,分页程序会转到cakephp/Posts/index/page:2。
在这里,你得到PostsController代码:
class PostsController extends AppController {
var $name = 'Posts';
public $helpers = array('Html', 'Form', 'Js', 'Paginator');
public $components = array('RequestHandler');
public $paginate = array(
'limit' => 5,
'maxLimit' => 50,
'order' => array(
'Post.INCOME' => 'asc',
),
);
function index() {
//debug($this->request->data);
//var_dump($this->params);
if(!empty($this->request->data['ajaxSearchAll'])){
if($this->RequestHandler->isAjax()){
//$data = $this->Post->find('all', array('conditions' => array('ZIPCODE LIKE' => '%' . $this->data['ajaxSearchAll'] . '%')));
$posts = $this->paginate('Post', array('ZIPCODE LIKE' => '%' . $this->data['ajaxSearchAll'] . '%'));
//$this->set('posts', $data);
$this->set(compact('posts'));
$this->render('SearchAll', 'ajax');
}
}
/// GOES ON WITH IRRELEVANT STUFF ///
下图显示了“search_all.ctp”的视图文件代码(调试转储显示了恰当的阵列应该如何):
如果你们中的任何人都能解决我的问题,我会非常感激。
更新1: 我给你的
debug($this->request->params['paging']);
它看起来精美绝伦的阵列。我必须用命名参数做些什么吗?我什么也没找到合适的食谱:-(
array(
'Post' => array(
'page' => (int) 1,
'current' => (int) 5,
'count' => (int) 11,
'prevPage' => false,
'nextPage' => true,
'pageCount' => (int) 3,
'order' => array(
'Post.INCOME' => 'asc'
),
'limit' => (int) 5,
'options' => array(
'conditions' => array()
),
'paramType' => 'named'
)
)
更新2:在index.ctp,阿贾克斯搜索开始的地方的代码查询和分页程序的第一页是完美的工作,但没有。该分页程序的按钮在所有:
<div id="courierQuery">
<?php echo $this->Form->create(false, array('type' => 'post', 'default' => false)); ?>
<?php echo $this->Form->input('ajaxSearchAll', array('type' => 'text', 'id' => 'ajaxSearchAll', 'name' => 'ajaxSearchAll', 'label' => false, 'placeholder' => 'Bitte PLZ eingeben'))?>
<?php $before = $this->Js->get('#loading')->effect('fadeIn', array('buffer' => False)); ?>
<?php $success = $this->Js->get('#loading')->effect('fadeOut', array('buffer' => False)); ?>
<?php echo $this->Js->get('#ajaxSearchAll')->event('keyup', $this->Js->request(
array('controller'=>'Posts', 'action'=>'index'),
array(
'update'=>'#erfolgreich_ajax',
'before' => $before,
'success' => $success,
'async' => true,
'dataExpression' => true,
'method' => 'post',
'data'=>$this->Js->serializeForm(array('isForm'=>'false', 'inline'=>'true'))
)
)
); ?>
<?php echo $this->Form->end();?>
</div>
/// IRRELEVANT STUFF ///
<div id="loading" style="display: none;">
<div style="float:left;margin-top: 14px"><?php echo $this->Html->image('ajax-loader.gif', array('id' => 'busy-indicator')); ?></div>
<div style="float:left;margin: 22px 0 0 10px;color: #fff"><p>Suche nach Inseraten läuft ...</p></div>
</div>
一开始,你不需要用分页助手类禁用选项,只生成并输出环节适当。 – Daniel
谢谢丹尼尔,我改变了这一点。但行为没有改变。 – Karl
我可以看到的另一件事 - 如果你在ajax更新之后,你必须在$ this中设置'update'=>'#content''(或类似的)和'evalscripts => true' - > Paginator-> options',然后在所述#content div中包围search_all.ctp。 – Daniel