Codeigniter型号
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeigniter型号相关的知识,希望对你有一定的参考价值。
class News_model extends Model { function News_model(){ parent::Model(); $this->table = 'news'; $this->order = 'post_date desc'; } foreach($this->fields as $field){ $this->$field = null; } } function select(){ $result = false; foreach($this->fields as $field){ if($this->$field){ $this->db->where($field, $this->$field); } } $this->db->order_by($this->order); $query = $this->db->get($this->table); if($this->post_id){ $result = $query->row(); } else{ $result = $query->result(); } return $result; } function update(){ $result = false; foreach($this->fields as $field){ $entry[$field] = $this->$field; } if($this->post_id){ $this->db->update($this->table, $entry); } else{ $this->db->insert($this->table, $entry); } return $result; } function insert(){ return $this->update(); } function delete(){ if($this->post_id){ $this->db->delete($this->table); } } } ?>
以上是关于Codeigniter型号的主要内容,如果未能解决你的问题,请参考以下文章