PHP code example of shiyang / yii2-infinite-scroll
1. Go to this page and download the library: Download shiyang/yii2-infinite-scroll library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shiyang / yii2-infinite-scroll example snippets
use shiyang\infinitescroll\InfiniteScrollPager;
echo ListView::widget([
...
'id' => 'my-listview-id',
'layout' => "{summary}\n<div class=\"items\">{items}</div>\n{pager}",
'pager' => [
'class' => InfiniteScrollPager::className(),
'widgetId' => 'my-listview-id',
'itemsCssClass' => 'items',
],
]);
use shiyang\infinitescroll\InfiniteScrollPager;
echo ListView::widget([
...
'id' => 'my-listview-id',
'layout' => "{summary}\n<div class=\"items\">{items}</div>\n{pager}",
'pager' => [
'class' => InfiniteScrollPager::className(),
'widgetId' => 'my-listview-id',
'itemsCssClass' => 'items',
'contentLoadedCallback' => 'afterAjaxListViewUpdate',
'nextPageLabel' => 'Load more items',
'linkOptions' => [
'class' => 'btn btn-lg btn-block',
],
'pluginOptions' => [
'loading' => [
'msgText' => "<em>Loading next set of items...</em>",
'finishedMsg' => "<em>No more items to load</em>",
],
'behavior' => InfiniteScrollPager::BEHAVIOR_TWITTER,
],
],
]);
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,
]);
}
use shiyang\infinitescroll\InfiniteScrollPager;
<div id="content">
foreach ($models as $model) {
// display $model here
}