在codeigniter中为where每个查询添加where子句

I have a situation where i have updated all database tables to include a new field called "siteid". Therefore i want to execute a where clause in every query generated by codeigniter.

Is there any way of doing this without manually adding the where clause in every model? Here is an example

$this->db->select('username');    
$this->db->where('userid');
$this->db->get('user');
$query->result_array();

I want to add a new where clause to every query so that it works like this

$this->db->select('username');    
$this->db->where('userid');
$this->db->where('siteid');
$this->db->get('user');
$query->result_array();

I'm not sure if there is a way to do it without doing it manually.

You could maybe just use search and replace current method with associative array method of where search. Documentation link

Search for

$this->db->where('userid');

and replace with

$this->db->where(['userid' => $userid, 'siteid' => $siteid]);

Create MY_Model.php inside core/ folder and make all your models extend MY_Model.

Then add this line:

$this->db->where('siteid');

into the constructor of MY_Model.php.

More info about extending core classes can be found here.