PHPackages                             sjaakp/yii2-swiper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sjaakp/yii2-swiper

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

sjaakp/yii2-swiper
==================

Swiper widget for Yii2.

1.0.4(4y ago)0240MITPHPPHP &gt;=7.0.0

Since Feb 21Pushed 4y ago1 watchersCompare

[ Source](https://github.com/sjaakp/yii2-swiper)[ Packagist](https://packagist.org/packages/sjaakp/yii2-swiper)[ RSS](/packages/sjaakp-yii2-swiper/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

Yii2-swiper
===========

[](#yii2-swiper)

#### Swiper widget for Yii2

[](#swiper-widget-for-yii2)

[![Latest Stable Version](https://camo.githubusercontent.com/d8c763123e0b3de593053c2a804d595329bd2694a73653927bfa07ce667ae7d5/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d7377697065722f762f737461626c65)](https://packagist.org/packages/sjaakp/yii2-swiper)[![Total Downloads](https://camo.githubusercontent.com/56a7042add07a507a55968a63eafa51aec12ac5f9ccfb13138c3e19205e48455/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d7377697065722f646f776e6c6f616473)](https://packagist.org/packages/sjaakp/yii2-swiper)[![License](https://camo.githubusercontent.com/f21f9afb34c91cb689dd7ba4cf77ca23e082d47f787096736d0d7c5226102b2e/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d7377697065722f6c6963656e7365)](https://packagist.org/packages/sjaakp/yii2-swiper)

This is a widget and associated behavior for [ActiveRecords](https://www.yiiframework.com/doc/api/2.0/yii-db-activerecord)in the [Yii 2.0](https://yiiframework.com/ "Yii") 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](https://getbootstrap.com/) is recommended in your site.

A demonstration of **yii2-swiper** is [here](https://sjaakpriester.nl/software/swiper).

Installation
------------

[](#installation)

The preferred way to install **yii2-swiper** is through [Composer](https://getcomposer.org/). 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](https://github.com/sjaakp/yii2-swiper/archive/master.zip).

Using Yii2-swiper
-----------------

[](#using-yii2-swiper)

**Yii2-swiper** consists of two classes: **PrevNextBehavior** and **Swiper**in namespace `sjaakp\swiper`.

#### PrevNextBehavior

[](#prevnextbehavior)

This is a [`Behavior`](https://www.yiiframework.com/doc/api/2.0/yii-base-behavior)for an [`ActiveRecord`](https://www.yiiframework.com/doc/api/2.0/yii-db-activerecord). It supplies the owning `ActiveRecord` with two methods:

- **getPrev()**: Returns an [`ActiveQuery`](https://www.yiiframework.com/doc/api/2.0/yii-db-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 the `ActiveRecord` attribute that defines the ordering.
    - If `[ '' => function($model) ]`: Function returning value of attribute.
- **$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:

```
