当前位置:编程学习 > php >>

qeephp内容分页

当列出查找的内容有很多条的时候我们可以将数据进行分页显示。

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
<div class="pt10">
02
        <a href="javascript:;" onclick="javascript:$(this).parent().next('div').toggle();" title="search >">Search >
03
        </a>
04
    </div>
05
    <!--search-->
06
    <div id="searchbox" style="display: none;" class="search_box">
07
      <a href="javascript:void(0);" onclick="javascript:$(this).parent().hide();" class="close2 f_r" title="close">close</a>
08
    <form name="city_search_form" action="#" method="get">
09
      <p>
10
         <label for="">Customer ID</label>
11
         <input class="text" name="cus_id" type="text">
12
      </p>
13
      <p>
14
          <label for="">First Name</label>
15
          <input name="first_name" class="text" type="text">
16
      </p>
17
      <p>
18
          <label for="">Last Name</label>
19
          <input name="last_name" class="text" type="text">
20
      </p>
21
      <p>
22
          <label for="">Email Address</label>
23
          <input name="email" class="text" type="text">
24
      </p>
25
       <p>
26
          <label for="">Program Code</label>
27
          <input name="code" class="text" type="text">
28
      </p>
29
      <p>
30
        <label> </label>
31
        <a onclick="city_search_form.submit();" title="" class="add_btn">Search</a>
32
     </p>
33
    </form>
34
    </div>
35
            

补充:Web开发 , php ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,