【问题标题】:CakePHP help with read()CakePHP 对 read() 的帮助
【发布时间】:2010-09-07 21:14:40
【问题描述】:

我正在关注blog tutorial 并对其进行修改以适应我网站的需求。我的视图功能有点问题。

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

此行不起作用,我收到此错误:警告(512):SQL 错误:1054:“where 子句”中的未知列“Article.id”[CORE/cake/libs/model/datasources/dbo_source.php ,第 681 行]

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

我的文章架构是

  • 文章编号
  • 用户名
  • 标题
  • 文字

查询有 WHERE Article.id = '1' 但是,那是错误的。它应该是 articleid 而不是 id

无论如何我都可以更改它以便使用 read()?

【问题讨论】:

    标签: cakephp


    【解决方案1】:

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

    来自the documentation

    每个表通常都有一个主键 id。您可以更改模型用作其主键的字段名称。这在设置 CakePHP 以使用现有数据库表时很常见。

    【讨论】:

    • 谢谢,这正是我要找的。​​span>
    猜你喜欢
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多