以下是显示来自数据库的图像的代码: -
<?php foreach($galleries as $gallery): ?>
<div class="col-md-4">
<div class="box-image">
<div class="image">
<?= $this->Html->image('/files/galleries/file_name/'.$gallery['file_directory'].'/lg_'.$gallery['file_name'],['id'=>'myImg','class'=>'img-fluid']); ?>
<div class="overlay d-flex align-items-center justify-content-center">
<div class="content">
<div class="name">
</div>
<div class="text">
<p class="buttons"><a href="#myModal" id="viewModal" type="button" data-toggle="modal" data-target="#myModal" class="btn btn-template-outlined">View</a>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
以下是模态代码: -
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Hello from Me!!!!!!!!! :p :p :p</p>
<p><?= $this->Html->image('/files/galleries/file_name/'.$gallery['file_directory'].'/lg_'.$gallery['file_name'],['id'=>'myImg','class'=>'img-fluid']); ?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
当我点击悬停图像时出现的“查看”链接时,模态会打开,它始终只显示数据库中的最后一个图像。 现在我希望如果我点击 viewA 的 View ,Modal应该在其中显示 imageA ,就像 imageB , imageC
答案 0 :(得分:0)
你不应该在Modal中使用PHP来显示Image(图像和所有东西都被加载到用户的浏览器中),尝试使用CSS + Script来显示模态。