1

所以经过很长一段时间和很多麻烦后,我终于让我的 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']); ?>&nbsp;</td>
                        <td><?php echo h($res['Stat']['clicks']); ?>&nbsp;</td>
                        <td><?php echo h($res['Stat']['conversions']); ?>&nbsp;</td>
                        <td><?php echo h($res['Stat']['payout']); ?>&nbsp;</td>
                        <td><?php echo h($res['Stat']['ltr']); ?>&nbsp;</td>
                        <td><?php echo h($res['Stat']['cpc']); ?>&nbsp;</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

4

2 回答 2

0

在您的控制器操作中,分页链接将检查请求是否在 ajax 中。如果通过 ajax 发出请求,则告诉控制器不要添加标头和其他 css 代码。

if($this->request->is('ajax'))
{ 
      $this->layout('ajax');
}
于 2013-09-04T08:41:47.173 回答
0

您的 html 标记无效。表格元素关闭太晚,只需移动

</table> 

<ul>

并删除最后一个 div 标签。

据我所知,您不必手动检查 ajax 请求。如果组件中包含 RequestHandler,则应自动选择相应的布局。

只需将以下内容添加到您的 AppController 中:

public $components = array('RequestHandler'); 
于 2013-09-04T10:53:43.970 回答