在 codeigniter 模型中保留表名称
在我的模型中,我使用如下所示的构造函数来设置它们
function Areas()
{
parent::Model();
$this->db->from("areas");
}
但是,如果我的模型的方法多次查询数据库,那么 FROM 子句看起来只包含在第一个查询中。有没有一种简单的方法可以为我的模型中运行的所有查询保留 FROM (除非我手动覆盖它)?
In my models I'm setting them up using constructors like the following
function Areas()
{
parent::Model();
$this->db->from("areas");
}
However, if a method of my model queries the database several times it looks like the FROM clause is only included in the first query. Is there an easy way to persist the FROM for all queries run within my model (unless I manually override it)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议不要这样做。这将导致以后很难消除错误。我猜这个问题与表名称的更改有更多关系?在这种情况下,您可以为每个表使用一个常量并在 config.php 中更改名称。
如果您只想节省一行代码,有时行数越多越好。这里就是这种情况。
I would advise against this. It would lead to REALLY hard to smush bugs later on down the line. The problem, I'm guessing, has more to do with the name of the table changing? In which case, you can use a constant for each table and change the name in config.
If you just wanted to save a line of code, sometimes more lines is better. This is the case here.