tomaivanovtomov/yii2-slider

Carousel 2.3.3

Installs: 31

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Language:HTML

Type:yii2-extension

1.1.3 2018-04-16 13:20 UTC

This package is not auto-updated.

Last update: 2024-04-17 01:50:30 UTC


README

yii2-slider

Yii2 slider is an extension with Owl Carousel 2.3.3 slider in it.
The slider has multilingual behaviour for title and description on each slide.

Installation

composer require tomaivanovtomov/yii2-revolution "^1.1.3"

Configuration

Add the Module class to `config.php`:
'modules' => [
    ....
    'user' => [
        'class' => 'tomaivanovtomov\slider\Module',
    ],
    ....
],

Add migrations

Create the two tables - `slide` and `slideLang`
php yii migrate/up --migrationPath=@vendor/tomaivanovtomov/yii2-slider/migrations

Register assets

Register revolution assets on top of your `layout\main.php`
\tomaivanovtomov\revolution\Assets::register($this);

Image path is set to www.example.com/frontend/web .

Usage

Call the widget and set the preferable options.
height - height of the slider.
slides - Images like an array of objects.

    public static function getSliderImages()
    {
        return \tomaivanovtomov\slider\models\Slide::find()
            ->joinWith('translation')
            ->select(['slide.id', 'slideLang.title', 'slide.filename'])
            ->where('slideLang.language=:lang', [':lang' => Yii::$app->language])
            ->all();
    } 
    echo \tomaivanovtomov\slider\widgets\Slider::widget([
        'slides' => \tomaivanovtomov\slider\models\Slide::getSliderImages(),
        'height' => 400,
        'options' => [
            'items' => 1
        ]
    ]);

All slider options can be seen at

https://owlcarousel2.github.io/OwlCarousel2/docs/api-options.html

Multilingual part

Copy these line in `params.php`:
'language-information' => [
    'BG' => [
        'title' => 'Български',
        'extension' => 'bg',
    ],
    'EN' => [
        'title' => 'English',
        'extension' => 'en',
    ],
],
'languageDefault' => 'bg'

This portion of code is linked with the multilingual model functionality. You can override the model and adapt it to your needs.