Codeigniter run query before a update
I have to run a query after every update and I want to know if there is a way to automate a $this->db->query() before every $this->db->update()
I'开发者_如何学JAVAm using it for log.
you can write your own function in the file core/MY_Model.php to do that:
function queryThenUpdate($query,$update)
{
$query = $this->db->query($query);
//use as you need $query
$this->db->update($update['table'],$update['data']);
}
where:
$queryis your actual query:SELECT * FROM ...$updateis an array of two elements$update['table']is the table to update and$update['data']is the updating data as specified on codeigniter active record's documentation
then make every model extend MY_Model
class Your_Model extend MY_Model
and every time you need to update something:
$this->Your_Model->queryThenUpdate($query,$update)
I believe you want to use codeigniters 'hook'
加载中,请稍侯......
精彩评论