【发布时间】:2020-09-20 16:36:00
【问题描述】:
到目前为止,我一直在使用 CI 3,并希望在新模型(在 CI 4 中)中分别处理多个数据库表(无连接)。
<?php namespace App\Models;
use CodeIgniter\Model;
class MyModel extends Model {
protected $table = 'main_table';
public function getAll($uid = false) {
return $this->where(['hidden' => '0'])
->where(['deleted' => '0'])
->findAll();
}
public function getMainImage($pid) {
return $this->from('another_table')
->where(['pid' => $pid])
->findAll();
}
}
由于某种原因,整个事情似乎没有成功。
有人可以帮我吗?
【问题讨论】:
-
你遇到了什么错误?
-
没有错误,但似乎 CI 使用了两个表(main_table 和 another_table)。我只想使用第二个。
-
在 getMainImage 中尝试设置 $this->table="another_table" 比不需要 from,但问题是如果你在这之后调用 getAll 我会查询 another_table 因为表名已经设置。
-
不幸的是,这个 CI 只查看“main_table”而完全忽略了“another_table”......
标签: codeigniter model