Yii框架中关于分页的信息

 
   
/**
*这是控制层
*/
namespace frontend\controllers;
use yii\web\Controller;
use yii\data\Pagination;
use yii\db\Query;
class DengController extends Controller
{
public function actionIndex()
{
$query = new Query();
$query->from("yi");
//这是模糊查询,如果需要多条件就多复制几份
if(!empty($w))
{
$query->andWhere(['like','name',"$w"]);
}
$pagination = new Pagination(['totalCount' => $query->count()]);
$pagination->setPageSize(3);
$user = $query->offset($pagination->offset)->limit($pagination->limit)->all();
return $this->render("index",['data'=>$user,'pagination'=>$pagination]);
}
}
/**
*这是视图层
*/
use yii\widgets\LinkPager;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
use yii\helpers\Html;

?>
$form=ActiveForm::begin([
    'action'=>Url::toRoute(['控制器/方法']),
    'method'=>'get',
]);
echo '搜索'," ",Html::input('text','g_name');
echo Html::submitButton('搜索');
ActiveForm::end();
?>
foreach ($data as $k => $v){
echo "
";
}
?>
name
".$v['name']."
echo LinkPager::widget([
'pagination'=>$pagination,
'nextPageLabel'=>'下一页',
'firstPageLabel'=>'首页',
]
)?>

你可能感兴趣的:(Yii框架中关于分页的信息)