我正在尝试使用cakephp和twitter bootsrap制作网站。对于我正在制作的画廊,我正在尝试使用foreach显示多个图像,但它们根本不显示。一切正常,foreach和可变数据,但回声不显示任何东西。有人可以帮忙吗? 提前致谢。 (代码来自我的show_images.ctp视图)
<table >
<tr>
<?php
$i=0;
foreach( $gallery_images as $gallery_image ):?>
<td align=center>
<?php echo "<a id=\"single_1\" href=\"test/".$gallery_image['GalleryImage']['path']." ";?>
<?php echo "<img src=\"test/".$gallery_image['GalleryImage']['path'].", alt=\"".$gallery_image['GalleryImage']['path']."";?>
<?php echo "</a>";?>
</td>
<?php $i++;?>
<?php
if($i==4){
echo "</tr><tr>";
$i=0;
}
?>
<?php endforeach ?>
</tr>
答案 0 :(得分:0)
你还没有在回声中关闭你的标签,试着改变这个:
<?php echo "<a id=\"single_1\" href=\"test/".$gallery_image['GalleryImage']['path']." ";?>
<?php echo "<img src=\"test/".$gallery_image['GalleryImage']['path'].", alt=\"".$gallery_image['GalleryImage']['path']."";?>
<?php echo "</a>";?>
到此:
<?php echo '<a id="single_1" href="test'.$gallery_image['GalleryImage']['path'].' >';?>
<?php echo '<img src="test'.$gallery_image['GalleryImage']['path'].'" alt="'.$gallery_image['GalleryImage']['path'].'" />';?>
<?php echo '</a>';?>