qeephp內容分頁_PHP教程

來源:互聯網
上載者:User
當列出尋找的內容有很多條的時候我們可以將資料進行分頁顯示。

user表的結構

現在要將使用者以列表的形式顯示,顯然不可能將查詢結果顯示在一頁當中,此時要將結果分頁顯示,首先將分頁控制項page.php複製到項目的control檔案中,然後我們可以在控制器中輸入如下代碼:

01
function actionCusList()
02
{
03
$cus_info = User::find();
04
//擷取當前是第幾頁
05
$page = intval( $this->_context->page );
06
$page<1?1:$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

02
Search >
03

04

05

06

07
close
08

34

35

36

37
_control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
38

39



















































40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 63 64 65 66
Cust. IDFirst NameLast NameEmail AddressProgramLast LoginAction

61
$cus['id']))?>" title="View">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

http://www.bkjia.com/PHPjc/478118.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478118.htmlTechArticle當列出尋找的內容有很多條的時候我們可以將資料進行分頁顯示。 user表的結構 現在要將使用者以列表的形式顯示,顯然不可能將查詢...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.