那么我该如何解决呢?它给了我:
注意 (8):未定义变量:产品 [APP/View/Categories/category_filter.ctp,第 10 行] 警告 (2):为 foreach() 提供的参数无效 [APP/View/Categories/category_filter.ctp,第 10 行]
<? if (!empty($categories)) { ?>
<? foreach($categories as $row): ?>
<h1>Category: <?= $row['Category']['category'] ?></h1>
<table>
<tr>
<th>Name</th><th>Description</th><th>Price</th><th>Category</th>
<th>Thumbnails</th>
</tr>
<? foreach($products as $row): ?>
<tr><<td>
<?=$row['Product']['name']?>
</td><td>
<?=$row['Product']['description']?>
</td><td>
<?=$row['Product']['price']?>
</td><td>
<?=$row['Product']['category_id']?>
</td><td>
<?
if(!empty($row['Picture'])){
?>
<?= $this->Html->image('/img/'. $row['Picture'][0]['filename'], array('width'=>'50', 'alt'=>$row['Picture'][0]['title'])); ?>
<p><?= $row['Picture'][0]['description']; ?></p>
<? } ?>
</td><tr>
<? endforeach; ?>
<? endforeach; ?>
</table>
<? } ?>
在控制器中
function category_filter($category_id) {
$this->set('categories',$this->Category->findAllById($category_id));
}