[英]How do I troubleshoot an “Undefined variable” notice in PHP?
I have two models: 'gallery' and 'image'. 我有两个模型:“图库”和“图像”。 When I try to fetch images from the galleries_controller I see this error:
当我尝试从galleries_controller获取图像时,我看到此错误:
Notice (8): Undefined variable: images [APP\\controllers\\galleries_controller.php, line 25]
注意(8):未定义的变量:images [APP \\ controllers \\ galleries_controller.php,第25行]
I use CakePHP's find
method to limit the images results. 我使用CakePHP的
find
方法来限制图像结果。
Here is my galleries_controller: 这是我的galleries_controller:
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid image', true));
$this->redirect(array('action' => 'index'));
}
$this->set('gallery', $this->Galley->read(null, $id));
/// this code have some problem ///
$this->loadModel('image');
$Images= $this->Image->find('all',
array(
'limit' => 2, //int
)
);
$this->set('images', $images);
}
The variable name is case sensitive ($Images and $images need to be all lowercase or all uppercase) 变量名称区分大小写($ Images和$ images必须全部小写或全部大写)
// you have a UPPERCASE I
$Images = $this->Image->find([...]
// you have a lowercase I
$this->set('images', $images);
Check your capitalization... 检查您的大小写...
$Images= $this->Image->find('all',
...
$this->set('images', $images);
$Images != $images $ Images!= $ images
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.