M
M
Miri_Skava2018-10-30 19:10:02
Yii
Miri_Skava, 2018-10-30 19:10:02

How to make image view through Carousel yii2?

Hello!
How to pass to the Carousel widget which image should be active now?
Controller code

namespace frontend\controllers;

use common\models\Photo;

class PhotoController extends \yii\web\Controller
{
    public function actionIndex()
    {
        $photos=Photo::find()->all();
        return $this->render('index',[
            'photos'=>$photos,
        ]);
    }

}

View Code
<?php

use yii\bootstrap\Modal;
use yii\bootstrap\Carousel;
?>
<h1 style="margin-top: 0" class="hea">Фотографии</h1>

<div >
    <?php
$i=0;
foreach ($photos as $ph) {
    echo '<a href = "#" data-toggle = "modal" data-target = "#' . $i . '" >';
    echo '<img style="border:2px white" height="100" class="i" src = "' . $ph->name . '" /> </a >';
    $car[$i]=[
        'content' => '<img style="text-align:center;height: 650px" src="'.$ph->name.'"/>',
        'caption' => '',
        'options' => []];
    $i++;
}
echo '</div>';
for($j=0;$j<$i;$j++) {
    Modal::begin([
        'id' => $j,
        'options'=>['class'=>'mod']
    ]);

    echo Carousel::widget([
        'items' => $car,
        'options' => [
            'class' => 'carousel slide',
            'data-interval' => '120000',
            'style'=>'height: 650px;width:max-content;',
        ],
    ]);

    Modal::end();
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-11-01
@webinar

We go to the docks and see that the person responsible for this is
https://getbootstrap.com/docs/3.3/javascript/#carousel
To control the rendering of items, there is
https://www.yiiframework.com/extension/yiisoft/yii...
it is also possible through js, there is a ready-made method for this:
https://getbootstrap.com/docs/3.3/javascript/#caro...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question