/**
*这是控制层
*/
<?php
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]);
}
}
/**
*这是视图层
*/
<?php
use yii\widgets\LinkPager;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
use yii\helpers\Html;
?>
<?php
$form=ActiveForm::begin([
'action'=>Url::toRoute(['控制器/方法']),
'method'=>'get',
]);
echo '搜索'," ",Html::input('text','g_name');
echo Html::submitButton('搜索');
ActiveForm::end();
?>
<table>
<input type="text" class="nn" name="sou">
<input type="submit" value="search">
<th>name</th>
<?php
foreach ($data as $k => $v){
echo "
<tr>
<td>".$v['name']."</td>
</tr>
";
}
?>
</table>
<?php
echo LinkPager::widget([
'pagination'=>$pagination,
'nextPageLabel'=>'下一页',
'firstPageLabel'=>'首页',
]
)?>
Yii框架中关于分页的信息
最新推荐文章于 2021-07-20 23:55:54 发布