0
我的畫廊模式是關係到我的圖像模型,但是當我retrive從galleries_controller我看不到任何結果,而是看這個錯誤圖片:CakePHP中查找相關數據
警告(二):提供對的foreach無效參數()[APP \視圖\畫廊\ 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; ?>
謝謝swiecki它的工作 – user1080247 2012-01-11 09:03:02