Answer the question
In order to leave comments, you need to log in
How to display images in Yii2 Carousel?
Tell me how to display images from the database, how to do it through the controller?
Output slider in Views.
<div class="row">
<?php echo Carousel::widget([
'items' => [
[
'content' => '<img style="" src="uploads/1.jpg"/>',
'caption' => '<h2>Yii Gii</h2><p>Удобный встроенный генератор кода. Модули, модели на основе таблиц в БД и, конечно же, CRUD</p>',
'options' => ['style' => 'height:500px;']
],
[
'content' => '<img style="" src="uploads/2.jpg"/>',
'caption' => '<h2>Yii Gii</h2><p>Удобный встроенный генератор кода. Модули, модели на основе таблиц в БД и, конечно же, CRUD</p>',
'options' => ['style' => 'height:500px;']
],
[
'content' => '<img style="" src="uploads/3.jpg"/>',
'caption' => '<h2>Yii Gii</h2><p>Удобный встроенный генератор кода. Модули, модели на основе таблиц в БД и, конечно же, CRUD</p>',
'options' => ['style' => 'height:500px;']
],
],
'options' => [
'style' => 'width:100%; padding-top:51px' // Задаем ширину контейнера
]
]);
?>
</div>
Answer the question
In order to leave comments, you need to log in
Form an array of $items in the controller, pass it to the view, and from there to the widget:
$items = [];
foreach(MySomeModel::find()->all() as $one){
$items[] = [
'content' => Html::img($one->imageUrl),
'caption' => $one->title,
'options' => ['style' => 'height:500px;']
],
}
return $this->render('someMyView',['items'=>$items]);
<div class="row">
<?php echo Carousel::widget([
'items' => $items,
'options' => [
'style' => 'width:100%; padding-top:51px' // Задаем ширину контейнера
]
]);
?>
</div>
How to set the number of images?
Let's say that for 1 display 2 images would be?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question