vim-snippets/snippets/codeigniter.snippets

172 lines
4.5 KiB
Plaintext
Raw Permalink Normal View History

2014-11-04 06:59:18 -05:00
# Based on nebjak/snipmate.vim/snippets/php.snippets
# Controller
snippet ci_controller
2014-11-07 09:48:03 -05:00
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ${1:ClassName} extends CI_Controller
{
function __construct()
{
2014-11-04 06:59:18 -05:00
parent::__construct();
${2:// code...}
}
2014-11-07 09:48:03 -05:00
function ${3:index}()
{
2014-11-04 06:59:18 -05:00
${4:// code...}
}
}
# Model
snippet ci_model
2014-11-07 09:48:03 -05:00
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ${1:ClassName_model} extends CI_Model
{
function __construct()
{
2014-11-04 06:59:18 -05:00
parent::__construct();
${2:// code...}
}
}
snippet ci_model_crudl
2014-11-07 09:48:03 -05:00
<?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...}
2014-11-07 09:48:03 -05:00
}
public function create($data)
2014-11-07 09:48:03 -05:00
{
2015-04-28 11:23:45 -04:00
if($this->db->insert($this->table, $data))
return true;
else
return false;
2014-11-07 09:48:03 -05:00
}
public function read($id)
2014-11-07 09:48:03 -05:00
{
2015-04-23 11:04:57 -04:00
return $this->db->get_where($this->table, array('id', $id))->result();
2014-11-07 09:48:03 -05:00
}
public function update($id, $data)
2014-11-07 09:48:03 -05:00
{
2015-04-28 11:23:45 -04:00
if($this->db->update($this->table, $data, array('id' => $id)))
2014-11-07 09:48:03 -05:00
return true;
else
return false;
}
public function delete($id)
2014-11-07 09:48:03 -05:00
{
if(is_array($id))
{
$this->db->trans_start();
foreach($id as $elem)
2015-04-28 11:23:45 -04:00
$this->db->delete($this->table, array('id' => $elem));
$this->db->trans_complete();
}
2014-11-07 09:48:03 -05:00
else
{
2015-04-28 11:23:45 -04:00
if($this->db->delete($this->table, array('id' => $id)))
return true;
else
return false;
}
}
public function listRows($limit = null, $offset = 0)
{
if(!is_null($limit))
$this->db->limit($limit, $offset);
2015-04-28 11:23:45 -04:00
return $this->db->get($this->table)->result();
2014-11-07 09:48:03 -05:00
}
}
2014-11-04 06:59:18 -05:00
# Load view
snippet ci_load-view
2014-11-04 06:59:18 -05:00
$this->load->view("${1:view_name}", $${2:data});${3}
# DB Class snippets
snippet ci_db-insert
2014-11-04 06:59:18 -05:00
$this->db->insert("${1:table}", $${2:data});${3}
snippet ci_db-select
2014-11-04 06:59:18 -05:00
$this->db->select("${1:id, ...}");${2}
snippet ci_db-from
2014-11-04 06:59:18 -05:00
$this->db->from("${1:table}");${2}
snippet ci_db-join
2014-11-04 06:59:18 -05:00
$this->db->join("${1:table}", "${2:condition}", "${3:type}");${4}
snippet ci_db-where
2014-11-04 06:59:18 -05:00
$this->db->where("${1:key}", "${2:value}");${3}
snippet ci_db-or_where
2014-11-04 06:59:18 -05:00
$this->db->or_where("${1:key}", "${2:value}");${3}
snippet ci_db-get
2014-11-04 06:59:18 -05:00
$this->db->get("${1:table}", ${2:limit}, ${3:offset});${4}
snippet ci_db-delete
2014-11-04 06:59:18 -05:00
$this->db->delete("${1:table}", "${2:where}");${3}
snippet ci_db-update
2014-11-04 06:59:18 -05:00
$this->db->update("${1:table}", $${2:set}, $${3:where});${4}
# Input Class snippets
snippet ci_input-post
2014-11-04 06:59:18 -05:00
$this->input->post("${1:index}");${2}
snippet ci_input-get
2014-11-04 06:59:18 -05:00
$this->input->get("${1:index}");${2}
snippet ci_input-cookie
2014-11-04 06:59:18 -05:00
$this->input->cookie("${1:index}");${2}
snippet ci_input-server
2014-11-04 06:59:18 -05:00
$this->input->server("${1:index}");${2}
snippet ci_input-user_agent
2014-11-04 06:59:18 -05:00
$this->input->user_agent();${1}
snippet ci_input-is_ajax_request
2014-11-04 06:59:18 -05:00
$this->input->is_ajax_request();${1}
snippet ci_input-is_cli_request
2014-11-04 06:59:18 -05:00
$this->input->is_cli_request();${1}
# Form Validation Class and Form Helper snippets
snippet ci_form_validation-set_rules
2014-11-04 06:59:18 -05:00
$this->form_validation->set_rules("${1:field}", "${2:label}", "${3:trim|required}");${4}
snippet ci_form_open
2014-11-04 06:59:18 -05:00
form_open("${1:action}");${2}
snippet ci_form_open_multipart
2014-11-04 06:59:18 -05:00
form_open_multipart("${1:action}");${2}
snippet ci_form_hidden
2014-11-04 06:59:18 -05:00
form_hidden("${1:name}", "${2:value}");${3}
snippet ci_form_input
2014-11-04 06:59:18 -05:00
form_input("${1:name}", "${2:value}");${3}
snippet ci_form_password
2014-11-04 06:59:18 -05:00
form_password("${1:name}", "${2:value}");${3}
snippet ci_form_upload
2014-11-04 06:59:18 -05:00
form_upload("${1:name}", "${2:value}");${3}
snippet ci_form_textarea
2014-11-04 06:59:18 -05:00
form_textarea("${1:name}", "${2:value}");${3}
snippet ci_form_dropdown
2014-11-04 06:59:18 -05:00
form_dropdown("${1:name}", $${2:options}, $${3:selected);${4}
snippet ci_form_checkbox
2014-11-04 06:59:18 -05:00
form_checkbox("${1:name}", "${2:value}");${3}
snippet ci_form_radio
2014-11-04 06:59:18 -05:00
form_radio("${1:name}", "${2:value}");${3}
snippet ci_form_submit
2014-11-04 06:59:18 -05:00
form_submit("${1:name}", "${2:value}");${3}
snippet ci_form_reset
2014-11-04 06:59:18 -05:00
form_reset("${1:name}", "${2:value}");${3}
snippet ci_form_button
2014-11-04 06:59:18 -05:00
form_button("${1:name}", "${2:value}");${3}
snippet ci_form_label
2014-11-04 06:59:18 -05:00
form_label("${1:label text}", "${2:id}");${3}
snippet ci_form_close
2014-11-04 06:59:18 -05:00
form_close();${1}
snippet ci_validation_errors
2014-11-04 06:59:18 -05:00
validation_errors();${1}
# Session Class snippets
snippet ci_session_userdata
2014-11-04 06:59:18 -05:00
$this->session->userdata("${1:item}");${2}
snippet ci_session_set_userdata
2014-11-04 06:59:18 -05:00
$this->session->set_userdata($${1:array});${2}
snippet ci_session_flashdata
2014-11-04 06:59:18 -05:00
$this->session->flashdata("${1:item}");${2}
snippet ci_session_set_flashdata
2014-11-04 06:59:18 -05:00
$this->session->set_flashdata("${1:item}", "${2:value}");${3}