Merge pull request #479 from rtorralba/master

Improved codeigniter.snippets (first ci php line and ci_model_crudl snippet)
This commit is contained in:
Honza Pokorny 2014-11-08 08:19:03 -04:00
commit bb36151e03

View File

@ -2,24 +2,139 @@
# Controller
snippet ci_controller
class ${1:ClassName} extends CI_Controller {
function __construct() {
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ${1:ClassName} extends CI_Controller
{
function __construct()
{
parent::__construct();
${2:// code...}
}
function ${3:index}() {
function ${3:index}()
{
${4:// code...}
}
}
# Model
snippet ci_model
class ${1:ClassName_model} extends CI_Model {
function __construct() {
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ${1:ClassName_model} extends CI_Model
{
function __construct()
{
parent::__construct();
${2:// code...}
}
}
snippet ci_model_crudl
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ${1:ClassName_model} extends CI_Model
{
private $table = '${2:table_name}';
function __construct()
{
parent::__construct();
${3:// code...}
}
// 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->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
$this->load->view("${1:view_name}", $${2:data});${3}