From 45d25d84cc2e1f4ac76cc236a72820cb064c5188 Mon Sep 17 00:00:00 2001 From: rtorralba Date: Sat, 8 Nov 2014 11:19:31 +0100 Subject: [PATCH] renamed ci_model_complet to ci_model_crudl and improved --- snippets/codeigniter.snippets | 95 +++++++++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 14 deletions(-) diff --git a/snippets/codeigniter.snippets b/snippets/codeigniter.snippets index 0fabcc5..7adf1e9 100644 --- a/snippets/codeigniter.snippets +++ b/snippets/codeigniter.snippets @@ -29,7 +29,7 @@ snippet ci_model ${2:// code...} } } -snippet ci_model_complet +snippet ci_model_crudl db->get($table)->result(); - } - - public function getRow($id) - { - return $this->db->get_where($table, array('id', $id))->result(); - } - - public function insert($data) + // public create(data) {{{ + /** + * create + * + * @param mixed $data + * @access public + * @return boolean + */ + public function create($data) { if($this->db->insert($table, $data)) return true; else return false; } + // }}} + // public read(id) {{{ + /** + * read + * + * @param int $id + * @access public + * @return boolean + */ + public function read($id) + { + return $this->db->get_where($table, array('id', $id))->result(); + } + // }}} + + // public update(id,data) {{{ + /** + * update + * + * @param int $id + * @param mixed $data + * @access public + * @return boolean + */ public function update($id, $data) { - if($this->db->where('id', $id)->update($table, $data)) + if($this->db->update($table, $data, array('id' => $id))) return true; else return false; } + // }}} + + // public delete(id) {{{ + /** + * delete + * + * @param mixed $id (int o array of int) + * @access public + * @return boolean + */ + public function delete($id) + { + if(is_array($id)) + { + $this->db->trans_start(); + foreach($id as $elem) + $this->db->delete($table, array('id' => $elem)); + $this->db->trans_complete(); + } + else + { + if($this->db->delete($table, array('id' => $id))) + return true; + else + return false; + } + } + // }}} + + // public listRows(limit=null,offset=0) {{{ + /** + * listRows + * + * @param int $limit + * @param int $offset + * @access public + * @return boolean + */ + public function listRows($limit = null, $offset = 0) + { + if(!is_null($limit)) + $this->db->limit($limit, $offset); + return $this->db->get($table)->result(); + } + // }}} } # Load view snippet ci_load-view