2012-01-07 39 views
0

我有两个模型:'画廊'和'图像'。当我尝试从galleries_controller获取图像我看到这个错误:如何解决PHP中的“未定义变量”通知?

Notice (8): Undefined variable: images [APP\controllers\galleries_controller.php, line 25]

我使用CakePHP的find方法来限制在图片搜索结果。

这里是我的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); 
} 
+0

'$ this-> loadModel('image');'是25行吗? – 2012-01-07 01:53:17

+0

$ this-> set('images',$ images);在行25 – user1080247 2012-01-07 01:54:34

回答

2

变量名称是区分大小写($图像和$图像必须全部小写或全部大写)

// you have a UPPERCASE I  
$Images = $this->Image->find([...] 

// you have a lowercase I 
$this->set('images', $images); 
+0

谢谢gabler..please另一个问题..你有任何方法旁边这种方法来找到限制图像或它是最好的方式 – user1080247 2012-01-07 02:00:05

+0

不知道,对不起。我不再使用CakePHP,现在我正在学习Zend Framework 2 =) – 2012-01-07 02:02:23

1

检查你的资本?

$Images= $this->Image->find('all', 
... 
$this->set('images', $images); 

$图片!= $图像