我有以下代码,它根据id从表“产品”中选择产品。控制器中未定义的索引(CakePhp)
public function p_details(){
$productIdNum = $this->params['detailID'];
//$this->Product->read(null, $productIdNum);
if(Validation::naturalNumber($productIdNum) == true){
$itemById = $this->Product->find('all', array('conditions' =>
array('Product.id' => $productIdNum)));
if(count($itemById) > 0){
$this->set('itemDetails', $itemById['Product']['id']);
}
}
}
但是,当我尝试打印变量“$ itemDetails”中查看, 像<?php echo $itemDetails['Product']['name']; ?>
它给我这个错误: 未定义指数:产品。如果我将它更改为 就像<?php echo $itemDetails['name']; ?>
它仍然给我同样的错误:未定义的索引:名称。 我无法弄清楚这一点。
可能的重复[参考 - 这个错误在PHP中意味着什么?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Nunser 2014-08-27 13:59:58
下一次你得到索引找不到错误,你可以在你的视图中执行'debug($ array);'来查看你的数组实际包含了什么。 – schnauss 2014-08-27 21:47:38