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.'%')