0
我試圖建立一個使用頁面控制器和admin_index()函數的管理頁面。我需要獲取具有特定狀態的所有帖子的列表並將其顯示在此頁面上。我怎樣才能在頁面控制器中抓住它們,然後我可以在視圖中顯示它們。CakePHP,獲取另一個模型的信息到頁面控制器
非常感謝提前。
我試圖建立一個使用頁面控制器和admin_index()函數的管理頁面。我需要獲取具有特定狀態的所有帖子的列表並將其顯示在此頁面上。我怎樣才能在頁面控制器中抓住它們,然後我可以在視圖中顯示它們。CakePHP,獲取另一個模型的信息到頁面控制器
非常感謝提前。
試試這個:
$this->loadmodel('Post');
$posts = $this->Post->find('all',array('conditions'=>array('Post.id'=>'1','Post.field'=>'value')));
$this->set('posts',$posts);
您可以加載模型在PagesController的admin_index()函數:
$this->loadModel('Post');
$posts = $this->Post->find('all', array(
'conditions' => array('Post.status' => 'your_filter')
);
$this->set(compact('posts'));
在自己的網頁視圖文件可現在你有$帖子。 (調整方法找到你的需求)