2010-09-07 78 views
0

我跟隨blog tutorial並修改它以適應我的網站的需求。我的觀看功能有點麻煩。CakePHP幫助閱讀()

function view($id = null) 
    { 
     $this->Article->articleid = $id; 
     $this->set('article', $this->Article->read()); 
    } 

這行不行,我得到這個錯誤:警告(512):SQL錯誤:1054:在未知列'Article.id 'where子句'[CORE /蛋糕/庫/模型/數據源/dbo_source.php,681]

但是,我得到它一起工作$this->set('article', $this->Article->find('first' , array('conditions' => array('Article.articleid' => $id))));

我的文章架構是

  • 條款ArticleID
  • 用戶ID
  • 標題
  • 文本

查詢已WHERE Articleid ='1' 但是,那是錯誤的。它應該是articleid而不是id

無論如何,我可以改變這個,所以我可以使用read()?

回答

4

您是否在文章模型中指定var $primaryKey = 'articleid';

the documentation

Each table normally has a primary key, id. You may change which field name the model uses as its primary key. This is common when setting CakePHP to use an existing database table.

+0

謝謝你,這就是我一直在尋找。 – Raptrex 2010-09-07 21:29:39