Download the PHP package sjaakp/yii2-swiper without Composer
On this page you can find all versions of the php package sjaakp/yii2-swiper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-swiper
Yii2-swiper
Swiper widget for Yii2
This is a widget and associated behavior for ActiveRecords in the Yii 2.0 PHP Framework. It allows the user to jump to neighbouring records by means of clicking, touch swiping, or using the left and right arrow keys.
Bootstrap 4 is recommended in your site.
A demonstration of yii2-swiper is here.
Installation
The preferred way to install yii2-swiper is through Composer.
Either add the following to the require section of your composer.json
file:
"sjaakp/yii2-swiper": "*"
Or run:
composer require sjaakp/yii2-swiper "*"
You can manually install yii2-swiper by downloading the source in ZIP-format.
Using Yii2-swiper
Yii2-swiper consists of two classes: PrevNextBehavior and Swiper
in namespace sjaakp\swiper
.
PrevNextBehavior
This is a Behavior
for an ActiveRecord
.
It supplies the owning ActiveRecord
with two methods:
- getPrev(): Returns an
ActiveQuery
to the previous record. - getNext(): Returns an
ActiveQuery
to the next record.
In other words, the owning ActiveRecord
now has two virtual properties:
- $prev: the previous record, or
null
if the current record is the first. - $next: the next record, or
null
if the current record is the last.
PrevNextBehavior has two properties:
-
$attribute
string|array
Has to be set.- If
string
: Name of theActiveRecord
attribute that defines the ordering. - If
[ '<attributeName>' => function($model) ]
: Function returning value of attribute.
- If
- $sort
SORT_ASC|SORT_DESC
Sets whether the order is incrementing or decrementing. Default:SORT_ASC
(incrementing).
PrevNextBehavior can be added to an ActiveRecord
like so:
<h1>...</h1>
...
<?= Swiper::widget([
'model' => $model,
'labelAttribute' => 'title',
// 'url' => 'view', // default
'registerLinkTags' => true
]) ?>
... other view code ...