2010-09-07 81 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