所以经过很长一段时间和很多麻烦后,我终于让我的 ajax 分页工作(有点)
现在我的 html 看起来像这样:
<?php
$this->Paginator->options(array(
'update' => '#content',
'evalScripts' => true,
));
?>
<div class="portlet box green Report index" id="content">
<div class="portlet-title">
<div class="caption"><i class="icon-globe"></i>Report Summary</div>
<div class="tools">
<a href="javascript:;" class="collapse"></a>
</div>
</div>
<div class="portlet-body">
<table class="table table-striped table-bordered table-hover table-full-width"
<thead>
<tr>
<th><?php echo $this->Paginator->sort('Offer.name','Offer'); ?></th>
<th><?php echo $this->Paginator->sort('Stat.clicks','Clicks'); ?></th>
<th><?php echo $this->Paginator->sort('Stat.conversions','Conversion'); ?></th>
<th><?php echo $this->Paginator->sort('Stat.payout','Payout'); ?></th>
<th><?php echo $this->Paginator->sort('Stat.ltr', 'What-isThis?'); ?></th>
<th><?php echo $this->Paginator->sort('Stat.cpc','Expected E-CPC'); ?></th>
</tr>
</thead>
<tbody class="report_data">
<?php foreach ($table['Report']['data']['data'] as $res): ?>
<tr>
<td><?php echo h($res['Offer']['name']); ?> </td>
<td><?php echo h($res['Stat']['clicks']); ?> </td>
<td><?php echo h($res['Stat']['conversions']); ?> </td>
<td><?php echo h($res['Stat']['payout']); ?> </td>
<td><?php echo h($res['Stat']['ltr']); ?> </td>
<td><?php echo h($res['Stat']['cpc']); ?> </td>
</tr>
<?php endforeach; ?>
</tbody>
<ul>
<?php if ($this->Paginator->hasPrev()): ?>
<li><?php echo $this->Paginator->first(__('First')) ?></li>
<li><?php echo $this->Paginator->prev(__('Prev'), array(), null, array('class' => 'prev disabled')) ?></li>
<?php
endif;
echo $this->Paginator->numbers(array('currentTag' => 'span', 'currentClass' => 'active',
'separator' => false, 'tag' => 'li', 'modulus' => 5));
if ($this->Paginator->hasNext()):
?>
<li><?php echo $this->Paginator->next(__('Next'), array(), null, array('class' => 'next disabled')) ?></li>
<li><?php echo $this->Paginator->last(__('Last')) ?></li>
<?php endif ?>
</table>
</ul>
</div>
</div>
</div>
<?php echo $this->Js->writeBuffer(); ?>
可悲的是我不能给你看图片(它说我缺乏声誉),但似乎当我按下分页时,它会将网站的内容放入 div 块中,这意味着视图变得混乱了很多!
谁能告诉我为什么会这样以及我该如何解决?
我尝试将 id='content' 移动到不同的 div 或 table 块但没有成功
蛋糕2.3版
我的索引操作
public function index()
{
if($this->request->is('ajax'))
{
$this->layout('ajax');
}else{
$this->layout = 'client_layout';
}
$startDate = $this->request->data['startDateTime'];
$endDate = $this->request->data['endDateTime'];
if($startDate == null || $startDate == '' ){
$startDate = date('y-m-d');
$endDate = date('y-m-d');
}
array_push($this->paginate['conditions']['Stat.date']['values'], $startDate, $endDate);
$this->set('table', $this->paginate());
}
更新
好的,所以在我的控制器中,我添加了以下内容:
if ($this->RequestHandler->isAjax()) {
$this->autoLayout = true;
$this->autoRender = true;
$this->layout = 'ajax';
}else{
$this->layout = 'client_layout';
}
现在这有所帮助,但它不是应该的 100%,现在它在表格顶部添加了一个 div 块,这里是一些 HTML 的样子:
<div id="updateTable">
<div class="portlet box red"> <-- VERY BAD!!
<div class="portlet-title">
<div class="portlet-body">
</div>
<div id="updateTable">
请注意,我还将 id 更改为 updateTable