//控制器方法
public function actionStrylist(){$username &#61; \Yii::$app->request->post(&#39;username&#39;); //接收搜索的数$where&#61;1;if(!empty($username)){$where &#61; " b_name like &#39;%$username%&#39;";}$page &#61; \Yii::$app->request->post(&#39;pages&#39;);//判断当前页码是否存在$pages &#61; isset($page) ? $page : 1 ;//计算总条数$count &#61; Brand::find()->count();//设置每一页显示的条数$pageSize &#61; 5 ;//计算总页数$pageSum &#61; ceil($count/$pageSize);//计算偏移量$offset &#61; ($pages - 1)*$pageSize;//计算上一页 下一页$last &#61; $pages<&#61;1 ? 1 : $pages-1 ;$next &#61; $pages>&#61;$pageSum ? $pageSum : $pages&#43;1 ;//拼接A链接$str &#61; &#39;&#39;;$str .&#61; "共"."$count"."项目 ".$pageSum."页 ";$str .&#61; "首页 ";$str .&#61; "上一页 ";$str .&#61; "下一页 ";$str .&#61; "尾页 ";$str .&#61; "第"."$pages"."页 ";//查询分页后的数据信息$sql &#61; "SELECT a.b_id,a.b_name,a.b_company,a.b_addtime,b.c_name,c.a_area,d.d_name,e.shop_name,f.t_price FROM brand a,cate b,area c,dustry d,shop_type e,tment_scope f where a.c_id&#61;b.c_id and a.r_id&#61;c.a_id and a.i_id&#61;d.d_id and a.t_id&#61;e.s_id and a.p_id&#61;f.t_id and $where limit $offset,$pageSize";$userInfo &#61; Brand::findBySql($sql)->asArray()->all();//搜索后关键字标红foreach($userInfo as $key &#61;> $value){$userInfo[$key][&#39;b_name&#39;] &#61; str_replace($username,"$username",$value[&#39;b_name&#39;]);}return $this->render(&#39;show&#39;,[&#39;arr&#39;&#61;>$userInfo,&#39;page&#39;&#61;>$str,&#39;username&#39;&#61;>$username]);}
show视图页
">
echo分页变量
script 搜索分页方法 //加载jQuery
function page(page){//获取搜索的数据var username &#61; $("#keyword").val();//发送AJAX请求 $.ajax({url:"index.php?r&#61;industry/strylist",data:{pages:page,username:username},type:"POST",success:function(msg){$("#body").html(msg);}});
}