Conflicts:
	snippets/codeigniter.snippets
This commit is contained in:
rtorralba 2015-04-23 17:09:50 +02:00
commit daf729a3d6

View File

@ -29,7 +29,7 @@ snippet ci_model
${2:// code...} ${2:// code...}
} }
} }
snippet ci_model_complet snippet ci_model_crudl
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ${1:ClassName_model} extends CI_Model class ${1:ClassName_model} extends CI_Model
@ -39,34 +39,101 @@ snippet ci_model_complet
function __construct() function __construct()
{ {
parent::__construct(); parent::__construct();
${2:// code...} ${3:// code...}
} }
public function getRows() // public create(data) {{{
/**
* create
*
* @param mixed $data
* @access public
* @return boolean
*/
public function create($data)
{ {
return $this->db->get($this->table)->result(); if($this->db->insert($table, $data))
return true;
else
return false;
} }
// }}}
public function getRow($id) // public read(id) {{{
/**
* read
*
* @param int $id
* @access public
* @return boolean
*/
public function read($id)
{ {
return $this->db->get_where($this->table, array('id', $id))->result(); return $this->db->get_where($this->table, array('id', $id))->result();
} }
// }}}
public function insert($data) // public update(id,data) {{{
{ /**
if($this->db->insert($this->table, $data)) * update
return true; *
else * @param int $id
return false; * @param mixed $data
} * @access public
* @return boolean
*/
public function update($id, $data) public function update($id, $data)
{ {
if($this->db->where('id', $id)->update($this->table, $data)) if($this->db->update($table, $data, array('id' => $id)))
return true; return true;
else else
return false; 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 # Load view
snippet ci_load-view snippet ci_load-view