【发布时间】:2012-08-25 04:28:29
【问题描述】:
我的 Gallery 模型与我的图像模型相关,但是当我从 gallery_controller 检索图像时,我看不到任何结果,而是看到此错误:
警告 (2):为 foreach() 提供的参数无效 [APP\views\galleries\view.ctp,第 35 行]
这是我的控制器操作中的代码:
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid gallery', true));
$this->redirect(array('action' => 'index'));
}
$this->set('gallery', $this->Gallery->read(null,$id));
$this->Gallery->Image->find('all',array('conditions' => array('Image.gallery_id'=> $id)));
$this->set('images', $images);
}
这是我的画廊/视图中用于遍历数组的循环。
<?php
$i = 0;
foreach ($images['Image'] as $image):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php $image['id'] ;?></td>
<td><?php echo $image['name'];?></td>
<!--<td><?php echo $image['img_file'];?></td>-->
<td><?php echo $html->image('uploads' . DS . 'images' . DS . $image['img_file'], array('alt' => 'Gallery Image')); ?></td>
</tr>
<?php endforeach; ?>
【问题讨论】:
标签: cakephp cakephp-2.0 cakephp-model