shiyang/yii2-infinite-scroll
Composer 安装命令:
composer require shiyang/yii2-infinite-scroll
包简介
Yii2 extension for infinite-scroll jQuery plugin
README 文档
README
Yii2 extension for infinite-scroll jQuery plugin, providing scrolling functionality for widgets such as ListView.
It renders a hyperlink that leads to subsequent page of a target and registers
infinite-scroll jQuery plugin which uses javascript to fetch and append content for subsequent pages,
gracefully degrading to complete page reload when javascript is disabled.
Several behaviours allowing to customize scroll behavior are provided out of the box, including twitter-style manual trigger, local scroll in overflow div, masonry integration and others.
Resources
- Yii2 extension page
- Infinite-Scroll jQuery plugin documentation
Installation
Composer
Add extension to your composer.json and update your dependencies as usual, e.g. by running composer update
{ "require": { "shiyang/yii2-infinite-scroll": "*" } }
##Widget Configuration
In addition to most of the properties that LinkPager provides, this widget also allows you to configure:
- $widgetId string owner widget id, required
- $itemsCssClass string CSS class of a tag that encapsulates items, required
- $pluginOptions array infinite-scroll jQuery plugin options. For more information refer to infinite-scroll documentation
- $contentLoadedCallback string|JsExpression javascript callback to be executed on loading the content via ajax call
##Sample Usage
Plugin works by appending fetched items to the end of parent container, so it is required
to configure layout property of parent ListView widget, wrapping {items} into e.g. div container with some class (to be used as a selector).
It is possible to configure all selectors that widget initializes plugin with to fit your project requirements, but it general it is enough to
set itemCssClass (class of that wrapping tag that we created) and widgetId (which would ensure multiple plugins on the same page would not conflict).
So the minimal required configuration would look like this:
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', ], ]);
An example illustrating how to customize some widget / plugin options:
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, ], ], ]);
Or
Controller action:
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,
]);
}
View:
use shiyang\infinitescroll\InfiniteScrollPager;
<div id="content">
<?php
foreach ($models as $model) {
// display $model here
}
?>
</div>
// display pagination
echo InfiniteScrollPager::widget([
'pagination' => $pages,
'widgetId' => '#content',
]);
##License
Extension is released under MIT license, same as underlying jQuery plugin.
shiyang/yii2-infinite-scroll 适用场景与选型建议
shiyang/yii2-infinite-scroll 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.1k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「jquery」 「plugin」 「widget」 「yii2」 「infinite-scroll」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shiyang/yii2-infinite-scroll 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shiyang/yii2-infinite-scroll 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shiyang/yii2-infinite-scroll 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
This is a laravel 4 package for the server and client side of datatables at http://datatables.net/
Add a weather widget to Flarum
A jQuery augmented PHP library for creating and validating HTML forms
Implementation of carouFredSel as extension for Contao Open Source CMS
统计信息
- 总下载量: 3.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-20