sufuyu 2017-04-29 10:10:17 1725次浏览 0条回复 0 0 0

分页没用model层, 控制器 PageController:

<?php  
namespace backend\controllers;
use yii\web\Controller;
use yii;
use db;
use yii\data\Pagination; 
use yii\filters\VerbFilter;
use yii\db\query;
/**
* 分页
*/
class PageController extends Controller
{
    public function actionPage(){
    	$where['house_title']=Yii::$app->request->get('house_title');
	    $query=new Query();
	    $query->from('house');
	 if(!empty($where['house_title'])){
	        $query->andFilterWhere(
	            ['like','house_title',$where['house_title']]
	        );
	    }
	    $users=$query->from('house')->all();
	    $pages = new Pagination(['totalCount' =>$query->count(),'pageSize'=>'3']);
	    $users = $query->offset($pages->offset)
	             ->limit($pages->limit)
	             ->all();
	    return  $this->render('index',[
	    	          'data'=>$users,
	    	          'where'=>$where,
	    	          'pages'=>$pages
	    	   ]);
         }	
    }
?>

viem 视图

<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
use yii\widgets\LinkPager;
?>
<table border="1">
<?php foreach ($data as $k => $v): ?>
	<tr>
	    <td><?= $v['house_id']?></td>
            <td><?= $v['house_title']?></td>
	</tr>
<?php endforeach ?>
</table>
<?php
echo LinkPager::widget([
    'pagination'=>$pages,
    'nextPageLabel'=>'下一页',
    'firstPageLabel'=>'首页'
])
?>

这就是简单分页,目前多表分页正在研究中

    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册