gpt4 book ai didi

php - CodeIgniter DataMapper 表名覆盖不起作用

转载 作者:行者123 更新时间:2023-11-30 22:20:25 24 4
gpt4 key购买 nike

我刚刚使用 CodeIgniter 设置了 DataMapper 并根据需要编写了模型。

但是我似乎遗漏了一些东西,因为当我运行查询时,DataMapper 看不到表名覆盖并认为根本没有表。

有趣的是,如果我删除覆盖,它会正常工作(尽管有一个错误说自动生成的表格不存在)。

模型代码:

class Activity extends Datamapper {

var $table = 'activity_log';

var $has_one = [
'user'
];

}

Controller 代码:

$activity = new Activity(1);

错误:

Error Number: 1064 
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right
syntax to use near 'WHERE `.`id` = 1' at line 2

SELECT * WHERE `.`id` = 1

正如我上面提到的,如果我删除 var $tables = 'activity_log';然后它会按原样推迟回寻找表“事件”。

最佳答案

Rules

DataMapper models must be named the singular version of the object name, with an uppercase first letter. So for a user object, the DataMapper model would be named User. The model should have a corresponding table in the database named as the lowercase, pluralised version of the object name. So for a DataMapper model named User, the table would be named users. For a DataMapper model named Country, the table would be named countries.

In most cases, the difference between the singular and plural version of an object name is just a matter of adding the letter s on the end.

您的模型应命名为 Activity_log

Docs .

关于php - CodeIgniter DataMapper 表名覆盖不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36756201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com