cakephp - Cakephp 2.x 搜索时分页错误
问题描述
我正在使用 cakephp 分页器组件来搜索数据。我能够检索数据,但是当我移动到下一页或排序时,我收到了一个错误。
注意 (8):未定义变量:auditLog [APP\View\Audits\filter_trails.ctp,第 92 行] 警告 (2):为 foreach() 提供的参数无效 [APP\View\Audits\filter_trails.ctp,第 92 行]
注意(8):未定义索引:count [CORE\Cake\View\Helper\PaginatorHelper.php,第 672 行] 注意(8):未定义索引:限制 [CORE\Cake\View\Helper\PaginatorHelper.php,第 675 行]注意(8):未定义索引:count [CORE\Cake\View\Helper\PaginatorHelper.php,第 676 行] 注意(8):未定义索引:count [CORE\Cake\View\Helper\PaginatorHelper.php,第 677 行]注意(8):未定义索引:当前 [CORE\Cake\View\Helper\PaginatorHelper.php,第 695 行] 注意(8):未定义索引:计数 [CORE\Cake\View\Helper\PaginatorHelper.php,第 696 行]第 1 页,共 1 页,显示总数中的记录。
这是我在控制器中的代码: public function filterTrails() {
if (isset($this->request->data['AuditFilter'])) {
$keywords = $this->request->data['AuditFilter']['keyword'];
$date_from = $this->request->data['AuditFilter']['date_from'];
$date_to = $this->request->data['AuditFilter']['date_to'];
if (!empty($date_from && !empty($date_to))){
$this->paginate = array(
'fields' => 'audit.event, audit.model, audit.created, audit.ip_address, auditchange.modifiedby,auditchange.column_name , auditchange.old_value, auditchange.new_value',
'joins' => array(
array(
'table' => 'audit_changes', 'alias' => 'auditchange', 'type' => 'Inner', 'conditions' => 'auditchange.audit_id = audit.id'
)
),
'conditions' => array(
'or' => array(
'Audit.event LIKE' => "%$keywords%" ,
'Audit.ip_address LIKE ' => "%$keywords%" ,
'Audit.model LIKE' => "%$keywords%"),
'AND' => array('Audit.created BETWEEN ? and ?' => array($date_from, $date_to))
)
);
} else {
$this->paginate = array(
'fields' => 'audit.event, audit.model, audit.created, audit.ip_address, auditchange.modifiedby,auditchange.column_name , auditchange.old_value, auditchange.new_value',
'joins' => array(
array(
'table' => 'audit_changes', 'alias' => 'auditchange', 'type' => 'Inner', 'conditions' => 'auditchange.audit_id = audit.id'
)
),
'conditions' => array(
'or' => array(
'Audit.event LIKE' => "%$keywords%",
'Audit.ip_address LIKE ' => "%$keywords%" ,
'Audit.model' => "%$keywords%",
'auditchange.modifiedby LIKE' => "%$keywords%")
)
);
}
$data = $this->Paginator->paginate('Audit');
$this->set('auditLog', $data);
然后在我看来,这就是我所做的:
<?php $this->Paginator->options(array('url' => $this->passedArgs)); ?>
<table class="table table-striped table-bordered dataTable"
role="grid" aria-describedby="basicExample_inf">
<thead>
<tr role="row">
<th style="width: 79.667px;"><?php echo $this->Paginator->sort('ip_address', 'Origin'); ?></th>
<th style="width: 79.3333px;"><?php echo $this->Paginator->sort('modifiedby','User'); ?></th>
<th style="width: 79.3333px;"><?php echo $this->Paginator->sort('created', 'Creation Time'); ?></th>
<th style="width: 100.667px;"><?php echo $this->Paginator->sort('event', 'Operation'); ?></th>
<th style="width: 100.667px;"><?php echo $this->Paginator->sort('model'); ?></th>
<th style="width: 100.667px;"><?php echo $this->Paginator->sort('column_name'); ?></th>
<!-- <th style="width: 50.333px;"><?php /*echo $this->Paginator->sort('old_value'); */?></th>
<th style="width: 50.333px;"><?php /*echo $this->Paginator->sort('new_value'); */?></th>-->
</tr>
</thead>
<tbody>
<?php foreach ($auditLog as $audit):; ?>
<tr>
<td><?php echo $audit['Audit']['ip_address']; ?></td>
<td><?php echo $audit['AuditChange'][0]['modifiedby']; ?></td>
<td><?php echo $audit['Audit']['created']; ?></td>
<td><?php echo $audit['Audit']['event']; ?></td>
<td><?php echo $audit['Audit']['model']; ?></td>
<td><?php echo $audit['AuditChange'][0]['column_name']; ?></td>
<!--<td style="width: 50.333px;"><?php /*echo $audit['AuditChange'][0]['old_value']; */?></td>
<td style="width: 50.333px;"><?php /*echo $audit['AuditChange'][0]['new_value']; */?></td>-->
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="row">
<div class="col-sm-12 col-md-5">
<div class="dataTables_info" id="basicExample_info" role="status"
aria-live="polite"><?php
echo $this->Paginator->counter(array('format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total.')
));
?>
</div>
</div>
<div class="col-sm-12 col-md-7">
<div class="dataTables_paginate paging_simple_numbers" id="basicExample_paginate">
<ul class="pagination">
<ul class="pagination justify-content-end">
<?php
echo $this->Paginator->prev('<i class = "fa fa-angle-double-left"> Previous</i>', array('escape' => false, 'tag' => 'li'), null, array('escape' => false, 'tag' => 'li', 'class' => 'page-item disabled', 'disabledTag' => 'a'));
echo $this->Paginator->numbers(array('separator' => '', 'currentTag' => 'a', 'currentClass' => 'active', 'tag' => 'li', 'first' => 1));
echo $this->Paginator->next('Next <i class = "fa fa-angle-double-right"></i>', array('escape' => false, 'tag' => 'li', 'currentClass' => 'disabled'), null, array('escape' => false, 'tag' => 'li', 'class' => 'disabled', 'disabledTag' => 'a', 'style' => 'display: inline-block; border: 1px solid #ddd;padding: 0.5em 1em'));
?>
</ul>
</ul>
</div>
</div>
</div>
谁能帮助我哪里出错了?
解决方案
推荐阅读
- rust - wgpu-rs:`线程'main'在'Texture [1]不存在'时惊慌失措'`
- reactjs - multer 给了我未定义的错误“原始名称”
- python - 如何在 Windows 10 上使用 python 包装 OpenSees CLI
- javascript - 如何根据选择将时刻设置为空
- parsing - 如何在独奏钢琴的 music21 中读取 midi / musicxml 文件,其中一个声音可以同时有多个音符?
- javascript - HTML/JavaScript 将字符串转换为数字
- java - 如何使用自定义绑定属性从 Java 客户端访问 SOAP 服务器
- python - 根据第一个数据帧的索引值添加第二个数据帧的值
- electron - Electron.NET CLI 发布到与 electron.manifest.json 文件中指定的目录不同的目录,而不是创建可执行文件和设置 exe
- javascript - 为什么当我有一个输出时,此代码在警报字段中显示两个结果?