找不到模型发布的数据库表帖子

时间:2010-05-04 09:19:53

标签: cakephp cakephp-1.2

我正在使用cakephp 1.26在我的localhost中创建一个简单的留言板 当我试图将两个表连接在一起时,我收到了这个错误:

Error:  Database table posts for model post was not found.

以下是两个表的表格结构:
表'post'包含以下字段{PostID,Topic,Content}
和表'reply'有这些字段{ReplyID,PostID,CreationDate}

以下是Model site1.php的代码:

<?php
class Site1 extends AppModel {   
    var $name = 'Site1';
    var $useTable = 'post';
    var $primaryKey = 'PostID';
    var $hasMany =  'Reply';
}
?>

这是Model reply.php的代码:

<?php
class Reply extends AppModel {       
    var $name = 'Reply';
    var $useTable = 'reply';
    var $primaryKey = 'ReplyID';
    var $belongsTo ='post';    
}
?>

你能帮我解决问题吗?

1 个答案:

答案 0 :(得分:3)

我认为你的$ belongsTo语句应该指向你的Site1模型(至少你没有提到有关Post模型的任何内容)。

顺便说一句:如果您可以控制数据库模式,我强烈建议您遵循CakePHP的naming conventions