YII2 列表( 不用自带的gridview) 分页+搜索
2016-01-25 12:42
615 查看
Controller
public function actionIndex()
{
$data = UserProfileSearch::search(Yii::$app->request->get());
//print_r($data->count());exit;
$pages = new Pagination(['totalCount' =>$data->count()]);
$model = $data->offset($pages->offset)->limit($pages->limit)->all();
return $this->render('index',compact('model','pages'));
}
View
然后循环数据
再加上<?= LinkPager::widget(['pagination' => $pages]); ?>
就好了
public function actionIndex()
{
$data = UserProfileSearch::search(Yii::$app->request->get());
//print_r($data->count());exit;
$pages = new Pagination(['totalCount' =>$data->count()]);
$model = $data->offset($pages->offset)->limit($pages->limit)->all();
return $this->render('index',compact('model','pages'));
}
UserProfileSearch.php
<?php namespace frontend\modules\company\models; use Yii; use common\models\user\UserProfile; use common\models\common\Common; /** * UserProfileSearch represents the model behind the search form about `common\models\user\UserProfile`. */ class UserProfileSearch { public static function search($params) { $query = UserProfile::find() ->select('i3a_user_profile.user_id,i3a_user_profile.fullname,i3a_user_profile.email,i3a_user_profile.position,i3a_user_profile.department_id,i3a_user.mobile,i3a_user.logged_at,i3a_user.created_at,i3a_user.status') ->joinWith('user','user_profile.user_id=user.id') //->joinWith('companyuserdepartment','user_profile.user_id=companyuserdepartment.user_id') ->andFilterWhere(['i3a_user.company_id'=>Yii::$app->user->identity->company_id]); if(isset($params['user_id'])){ $query->andFilterWhere(['i3a_user_profile.user_id'=>$params['user_id']]); } if(isset($params['nickname']) && $nickname = Common::POST_CHECK($params['nickname'])){ $query->andFilterWhere(['like', 'i3a_user_profile.fullname', $nickname]); } return $query; } }
View
然后循环数据
再加上<?= LinkPager::widget(['pagination' => $pages]); ?>
就好了
相关文章推荐
- yii2中使用Active Record模式的方法
- 从零开始学YII2框架(四)扩展插件yii2-kartikgii
- 从零开始学YII2框架(三)扩展插件yii2-gird
- 从零开始学YII2框架(五)快速生成代码工具 Gii 的使用
- Yii2使用小技巧之通过 Composer 添加 FontAwesome 字体资源
- Yii2隐藏frontend/web和backend/web的方法
- 从零开始学YII2框架(二)通过 Composer 安装扩展插件
- yii2框架中使用下拉菜单的自动搜索yii-widget-select2实例分析
- Yii2框架引用bootstrap中日期插件yii2-date-picker的方法
- yii2中添加验证码的实现方法
- Yii2 操作不同的数据库
- Yii2 自定义过滤器
- 使用 yii2-detail-view 扩展修改/删除/查看模型数据
- YII2 输出 执行的 SQL 语句,直接用程序输出
- 使用yii2 composer更新后报错 ::addRules()
- yii2 Activeform
- yii2 session的使用方法
- ActiveRecord Relation, 通过第三张表建立的关系
- ActiveRecord, Lazy and Eager Loading