我正在搜索如何使用LinkPage小部件在Yii2中创建寻呼机。
有什么例子吗?我是Yii的新人,所以任何帮助都会很好。
答案 0 :(得分:42)
很简单
$dataProvider = new ActiveDataProvider([
'query' => User::find(),
'pagination' => array('pageSize' => 50),
]);
echo \yii\widgets\LinkPager::widget([
'pagination'=>$dataProvider->pagination,
]);
或者如果你不使用dataProvider,你应该使用它:
$query = User::find();
$pagination = new Pagination(['totalCount' => $query->count(), 'pageSize'=>30]);
echo \yii\widgets\LinkPager::widget([
'pagination' => $pagination,
]);
答案 1 :(得分:4)
在控制器中:
function actionIndex()
{
$query = Article::find()->where(['status' => 1]);
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count()]);
$models = $query->offset($pages->offset)
->limit($pages->limit)
->all();
return $this->render('index', [
'models' => $models,
'pages' => $pages,
]);
}
在视图文件中:
foreach ($models as $model) {
// display $model here
}
// display pagination
echo LinkPager::widget([
'pagination' => $pages,
]);
答案 2 :(得分:0)
下面对于添加分页来说太简单了,
我们只需要添加控制器,
$dataProvider = new ActiveDataProvider([
'query' => Post::find(),
'pagination' => [
'pageSize' => 20,
],
]);
Yii2将在索引页上显示分页, https://yii2-framework.readthedocs.io/en/stable/guide/output-data-widgets/
答案 3 :(得分:0)
在您的控制器中
n <- c(10,20,30,40)
j <- 1:n
r <- 1.06
A <- r^j
A
sum(A)