我在控制器中编写了用于分页的代码,并列出了所有正常工作的产品类别。我有产品类别过滤器。过滤器也可以正常工作。现在分页限制为5。我搜索Apple产品类别,共有15条记录即将到来。当我单击分页中的第二页时,该页面将刷新,因此未应用过滤器,并且总记录即将到来。
$user_roles = $this->Role->find("all")->toArray();
$searchParams = $this->request->data();
$conditions = array();
if(!empty($searchParams)) {
if(!empty($searchParams['first_name'])) {
$conditions['firstname like'] = trim("%".$searchParams['first_name']."%", " ");
}
if(!empty($searchParams['status'])) {
$conditions['status'] = $searchParams['status'];
}
if(!empty($searchParams['role'])) {
$conditions['role'] = $searchParams['role'];
}
if(!empty($searchParams['status'])) {
$conditions['status'] = trim($searchParams['status'], " ");
}
}
try {
$users = $this->paginate($this->Users->find("all")->where(array('role NOT IN'=> ['director'], $conditions)));
} catch (NotFoundException $e) {
}
$this->set(compact('users', 'searchParams', 'user_roles'));
答案 0 :(得分:0)
过滤器表单方法必须是“获取”而不是“发布”,然后您将在每次刷新页面上设置过滤器。您将需要更改此行
$searchParams = $this->request->data();
对此:
$searchParams = $this->request->getQuery();