2011-10-27 45 views
0

顯示數據我想顯示從表games_reviews數據,而是我從桌上游戲中獲取數據,下面是控制器我使用CakePHP會不會從右表

class GamesReviewsController extends AppController { 

var $uses = array('Game', 'GamesVideo', 'games_reviews', 'GamesVideosType', 'GamesRewiewTypes','GamesGenre','User'); 


public function view() { 
    //$this->layout = 'pages'; 
    $this->set('columns', 1); 
    $url = $this->params['game_url']; 
    $game = $this->Game->findByUrl($url); 
    //render not found 

    $videos = Set::combine($game['GamesVideo'], '{n}.id', '{n}', '{n}.position'); 
    if (!empty($game['Game']['amazon_iframe'])) { 
     $this->set('xtraDiv', array('Buy Game' => array('type' => 'iframe', 'content' => $game['Game']['amazon_iframe']))); 
    } 
    $this->set('game', $game); 
    $this->set('videos', $videos); 



} 

}

回答

2

第一,刪除$ uses數組,這不是必需的。

您也可能想要爲您的模型使用Containable行爲。

總之,在控制器,你的代碼應該是這樣的:

$conditions = array('url' => $url); 
$gamesReviews = $this->GamesReview->find('first', compact('conditions')); 

我建議你採取的時間重新讀取CakePHP的食譜,瞭解這將大大幫助。

+0

謝謝,我會做 – user974435