improved some snippets

This commit is contained in:
rtorralba 2014-11-07 15:48:03 +01:00
parent ba77d58d08
commit 5271ea5a1d

View File

@ -2,24 +2,72 @@
# Controller # Controller
snippet ci_controller snippet ci_controller
class ${1:ClassName} extends CI_Controller { <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function __construct() {
class ${1:ClassName} extends CI_Controller
{
function __construct()
{
parent::__construct(); parent::__construct();
${2:// code...} ${2:// code...}
} }
function ${3:index}() { function ${3:index}()
{
${4:// code...} ${4:// code...}
} }
} }
# Model # Model
snippet ci_model snippet ci_model
class ${1:ClassName_model} extends CI_Model { <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function __construct() {
class ${1:ClassName_model} extends CI_Model
{
function __construct()
{
parent::__construct(); parent::__construct();
${2:// code...} ${2:// code...}
} }
} }
snippet ci_model_complet
<?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();
${2:// code...}
}
public function getRows()
{
return $this->db->get($table)->result();
}
public function getRow($id)
{
return $this->db->get_where($table, array('id', $id))->result();
}
public function insert($data)
{
if($this->db->insert($table, $data))
return true;
else
return false;
}
public function update($id, $data)
{
if($this->db->where('id', $id)->update($table, $data))
return true;
else
return false;
}
}
# Load view # Load view
snippet ci_load-view snippet ci_load-view
$this->load->view("${1:view_name}", $${2:data});${3} $this->load->view("${1:view_name}", $${2:data});${3}