我正在使用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';
}
?>
你能帮我解决问题吗?
答案 0 :(得分:3)
我认为你的$ belongsTo语句应该指向你的Site1模型(至少你没有提到有关Post模型的任何内容)。
顺便说一句:如果您可以控制数据库模式,我强烈建议您遵循CakePHP的naming conventions。