yii中widget分页的用法

本文介绍了在Yii框架中实现分页功能的具体步骤。包括在控制器中设置分页参数、查询数据库并传递数据到视图,以及在视图中使用widget显示分页链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

yii中widget分页的用法


1首先controller的action

    $count = Listdetail::model()->count("listId=:listId",array(':listId'=>$listid));
$pages=new CPagination($count);
$pages->pageSize=20;
$criteria=new CDbCriteria();
$pages->applyLimit($criteria);
$result=Listdetail::model()->findAll("listId=:listId limit :offsit,:limit",
        array(':listId'=>$listid,':offsit'=>$pages->currentPage*$pages->pageSize,':limit'=>$pages->pageSize));

            $this->render('viewlistdetail', array(
                    'emaillist'=>$result,
                    'pages'=>$pages,
                    'list_id'=>$listid
   ));

2。views

<?php

//输出列表

$table = new SimpleTable();
$table->set_header("编号");
$table->set_header("邮件地址");
$table->set_header("操作");
$table->echo_table_header();

if(isset ($emaillist)){
    $i = 1;
    foreach ($emaillist as $row){
        $listid = $row['listid'];
        $email = $row['email'];
      $table->echo_td($i);
       $table->echo_td($email);
       $link = "";
       $delurl = "index.php?r=email/deleteemail&listid=".$listid."&email=".$email;
       $dellink = $componentTools->DelLink("删除", $delurl);
       $link .=$dellink;
        $table->echo_td($link);
        $table->end_row();

        $i++;
    }
}

$table->echo_table_floor();
$_REQUEST['listid'] = $list_id;

//widget输出分页的操作标签

?>
<?php $this->widget('CLinkPager',array('pages'=>$pages));?>

 

还有一个地方就是 sql中 and email like ‘%abc%'.在yii中写法为:and email like :email

array(':email'=>'%'.$email.'%')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值