使用cakephp,如何在foreach循环中显示存储在数据库中的图像


Using cakephp how do you display an image stored in the database in a foreach loop?

我是Cakephp的新手,我想知道如何在foreach循环中从数据库中回显图像?我该怎么做?什么是正确的方法?我所有的图片都在webroot文件夹中。

<?php if ( isset($beefwellington) ){ ?>
       <?php foreach ($beefwellington as $wellington): ?>
        <h1><?php echo $wellington['Beef']['genre']; ?></h1>
        <h2><?php echo $wellington['Beef']['story']; ?></h2>
            <?php endforeach; ?>
            <?php } ?>

这就是我尝试的:

<?php echo $html->image('app/webroot/img' .$wellington['Beef']['picture'],    array('alt' => 'story image'));

在我的数据库中,图像的存储方式如下"pumkin.jpg"

如果你的图像在app/webtoot/img文件夹中,那么你只需要这样写:

<?php echo $this->Html->image($wellington['Beef']['picture'], array('alt' => 'story image')); ?>