PHP code example of black-lamp / yii2-slider
1. Go to this page and download the library: Download black-lamp/yii2-slider 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/ */
black-lamp / yii2-slider example snippets
'modules' => [
// ...
'slider' => [
'class' => bl\slider\backend\Module::class
]
]
<?= bl\slider\frontend\widgets\SliderWidget::widget([
'sliderKey' => 'home-page-slider'
])
use yii\db\ActiveRecord;
/**
* @property string $sliderKey
* @property SliderContent[] $sliderContent
*/
class Article extends ActiveRecord
{
public function behaviors()
{
return [
// ...
'slider' => [
'class' => \bl\slider\common\behaviors\SliderBehavior::class
],
];
}
}
$article = new Article();
$article->sliderKey = "article-slider";
$slide_one = new SliderContent();
$slide_one->content = "img/slider/slider-1.jpg";
$slide_one->position = 1;
$slide_two = new SliderContent();
$slide_two->content = "img/slider/slider-2.jpg";
$slide_two->position = 2;
// slide N...
$article->sliderContent = $slide_one;
$article->sliderContent = $slide_two;
// or
$article->sliderContent = [$slide_one, $slide_two];
$article->save();