1

我正在使用 cakephp 1.26 在我的本地主机中创建一个简单的留言板。
当我尝试将两个表链接在一起时,出现此错误:

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

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

这是模型site1.php的代码:

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

这是模型reply.php的代码:

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

你能帮我解决问题吗?

4

1 回答 1

3

我认为你的 $belongsTo 声明应该指向你的 Site1 模型(至少你没有提到任何关于 Post 模型的东西)。

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

于 2010-05-04T09:37:59.350 回答