当列出查找的内容有很多条的时候我们可以将数据进行分页显示。
user表的结构如图:
现在要将用户以列表的形式显示,显然不可能将查询结果显示在一页当中,此时要将结果分页显示,首先将分页控件page.php复制到项目的control文件中,然后我们可以在控制器中输入如下代码:
01
function actionCusList()
02
{
03
$cus_info = User::find();
04
//获取当前是第几页
05
$page = intval( $this->_context->page );
06
$page
07
//设置每页显示的数量
08
$page_size = 10;
09
10
//按条件查找用户
11
if($id = $this->_context->get('cus_id'))
12
$cus_info->where('id = ?', $id);
13
else
14
{
15
if($first_name = $this->_context->get('first_name'))
16
$cus_info->where('first_name = ?', $first_name);
17
18
if($last_name = $this->_context->get('last_name'))
19
$cus_info->where('last_name = ?', $last_name);
20
21
if($email = $this->_context->get('email'))
22
$cus_info->where('email = ?', $email);
23
24
if($code = $this->_context->get('code'))
25
$cus_info->where('pro_id = ?', Program::find('code = ?', $code)->getOne()->id);
26
}
27
28
$cus_info->limitPage($page, $page_size);
29
$cus = $cus_info->getAll();
30
31
//渲染视图
32
$this->_view['url_args'] = $this->_context->get();
33
$this->_view['pagination'] = $cus_info->getPagination();
34
$this->_view['cus'] = $cus;
35
}
此代码中有一处是按条件查找用户,我们可以进行前台设计一个表单让用户输入特定条件来查找用户,代码如下:
01
05
06
35
36
37
_control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
38
39
Cust. ID | First Name | Last Name | Email Address | Program | Last Login | Action |
---|---|---|---|---|---|---|
61 View 62 |
67
68
_control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
69
分页关键代码为:
1
_control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
显示结果如图:
作者:frylan

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

Dreamweaver Mac版
시각적 웹 개발 도구

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경
