2012-01-07 134 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); 

$圖片!= $圖像