我似乎无法理解为什么分页不起作用其他一切都很好但我在视图中没有得到分页导航,我认为这会自动发生,但有人可以帮忙吗?
MODEL
public $actsAs = array(
'Search.Searchable'
);
public $filterArgs = array(
array(
'name' => 'username',
'type' => 'query',
'method' => 'filterName',
'defaultValue' => 'all'
) ,
array(
'name' => 'category2',
'type' => 'query',
'method' => 'filterCategory',
'defaultValue' => 'all'
) ,
'creationDateBetween' => array(
'type' => 'expression',
'method' => 'formatStartDate',
'field' => 'Post.created >= ?'
) ,
'creationDateBetween2' => array(
'type' => 'expression',
'method' => 'formatEndDate',
'field' => 'Post.created <= ?'
)
);
public
function formatStartDate($data = array())
{
$date = implode('-', array(
$data['creationDateBetween']['year'],
$data['creationDateBetween']['month'],
$data['creationDateBetween']['day']
));
return array(
$date
);
}
public
function formatEndDate($data = array())
{
$date = implode('-', array(
$data['creationDateBetween2']['year'],
$data['creationDateBetween2']['month'],
$data['creationDateBetween2']['day']
));
return array(
$date
);
}
public
function filterName($data, $field = null)
{
if (empty($data['username'])) {
return array();
}
$nameField = '%' . $data['username'] . '%';
return array(
'OR' => array(
$this->alias . '.username LIKE' => $nameField,
)
);
}
public
function filterCategory($data, $field = null)
{
if (empty($data['category2'])) {
return array();
}
$categoryField = '%' . $data['category2'] . '%';
return array(
'OR' => array(
$this->alias . '.category LIKE' => $categoryField,
)
);
}
控制器:
public $components = array(
'Session',
'Search.Prg',
'CsvView.CsvView'
);
public $presetVars = array(
array(
'field' => 'username',
'type' => 'value'
) ,
array(
'field' => 'category2',
'type' => 'value'
) ,
array(
'field' => 'creationDateBetween',
'type' => 'value'
) ,
array(
'field' => 'creationDateBetween2',
'type' => 'value'
) ,
);
public
function index()
{
$this->Prg->commonProcess();
$this->paginate = array(
'conditions' => $this->Post->parseCriteria($this->Prg->parsedParams())
);
$this->set('posts', $this->paginate());
}
查看
<!-- Here is where we loop through our $posts array, printing out post info -->
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id']; ?></td>
<td><?php echo $this->Form->postLink(
'Delete',
array('action' => 'delete', $post['Post']['id']),
array('confirm' => 'Are you sure?'));
?></td>
<!-- <td><?php echo $this->Html->link('Edit', array('action' => 'edit', $post['Post']['id'])); ?></td>-->
<td><?php echo $post['Post']['username']; ?></td>
<td><?php echo $post['Post']['created']; ?></td>
<td><?php echo $post['Post']['territory']; ?>
<td><?php echo $post['Post']['category']; ?></td>
<td><?php echo $post['Post']['a1']; ?></td>
<td><?php echo $post['Post']['a2']; ?></td>
<td><?php echo $post['Post']['b1']; ?></td>
<td><?php echo $post['Post']['b2']; ?></td>
<td><?php echo $post['Post']['c']; ?></td>
<?php endforeach; ?>
<?php unset($post); ?>
</table>