mirror of
				https://github.com/amix/vimrc
				synced 2025-10-31 06:33:35 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			172 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			172 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| # Based on nebjak/snipmate.vim/snippets/php.snippets
 | |
| 
 | |
| # Controller
 | |
| snippet ci_controller
 | |
| 	<?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}()
 | |
| 		{
 | |
| 			${4:// code...}
 | |
| 		}
 | |
| 	}
 | |
| # Model
 | |
| snippet ci_model
 | |
| 	<?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 function create($data)
 | |
| 		{
 | |
| 			if($this->db->insert($this->table, $data))
 | |
| 				return true;
 | |
| 			else
 | |
| 				return false;
 | |
| 		}
 | |
| 
 | |
| 		public function read($id)
 | |
| 		{
 | |
| 			return $this->db->get_where($this->table, array('id', $id))->result();
 | |
| 		}
 | |
| 
 | |
| 		public function update($id, $data)
 | |
| 		{
 | |
| 			if($this->db->update($this->table, $data, array('id' => $id)))
 | |
| 				return true;
 | |
| 			else
 | |
| 				return false;
 | |
| 		}
 | |
| 
 | |
| 		public function delete($id)
 | |
| 		{
 | |
| 			if(is_array($id))
 | |
| 			{
 | |
| 				$this->db->trans_start();
 | |
| 				foreach($id as $elem)
 | |
| 					$this->db->delete($this->table, array('id' => $elem));
 | |
| 				$this->db->trans_complete();
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				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);
 | |
| 			return $this->db->get($this->table)->result();
 | |
| 		}
 | |
| 	}
 | |
| # Load view
 | |
| snippet ci_load-view
 | |
| 	$this->load->view("${1:view_name}", $${2:data});${3}
 | |
| # DB Class snippets
 | |
| snippet ci_db-insert
 | |
| 	$this->db->insert("${1:table}", $${2:data});${3}
 | |
| snippet ci_db-select
 | |
| 	$this->db->select("${1:id, ...}");${2}
 | |
| snippet ci_db-from
 | |
| 	$this->db->from("${1:table}");${2}
 | |
| snippet ci_db-join
 | |
| 	$this->db->join("${1:table}", "${2:condition}", "${3:type}");${4}
 | |
| snippet ci_db-where
 | |
| 	$this->db->where("${1:key}", "${2:value}");${3}
 | |
| snippet ci_db-or_where
 | |
| 	$this->db->or_where("${1:key}", "${2:value}");${3}
 | |
| snippet ci_db-get
 | |
| 	$this->db->get("${1:table}", ${2:limit}, ${3:offset});${4}
 | |
| snippet ci_db-delete
 | |
| 	$this->db->delete("${1:table}", "${2:where}");${3}
 | |
| snippet ci_db-update
 | |
| 	$this->db->update("${1:table}", $${2:set}, $${3:where});${4}
 | |
| # Input Class snippets
 | |
| snippet ci_input-post
 | |
| 	$this->input->post("${1:index}");${2}
 | |
| snippet ci_input-get
 | |
| 	$this->input->get("${1:index}");${2}
 | |
| snippet ci_input-cookie
 | |
| 	$this->input->cookie("${1:index}");${2}
 | |
| snippet ci_input-server
 | |
| 	$this->input->server("${1:index}");${2}
 | |
| snippet ci_input-user_agent
 | |
| 	$this->input->user_agent();${1}
 | |
| snippet ci_input-is_ajax_request
 | |
| 	$this->input->is_ajax_request();${1}
 | |
| snippet ci_input-is_cli_request
 | |
| 	$this->input->is_cli_request();${1}
 | |
| # Form Validation Class and Form Helper snippets
 | |
| snippet ci_form_validation-set_rules
 | |
| 	$this->form_validation->set_rules("${1:field}", "${2:label}", "${3:trim|required}");${4}
 | |
| snippet ci_form_open
 | |
| 	form_open("${1:action}");${2}
 | |
| snippet ci_form_open_multipart
 | |
| 	form_open_multipart("${1:action}");${2}
 | |
| snippet ci_form_hidden
 | |
| 	form_hidden("${1:name}", "${2:value}");${3}
 | |
| snippet ci_form_input
 | |
| 	form_input("${1:name}", "${2:value}");${3}
 | |
| snippet ci_form_password
 | |
| 	form_password("${1:name}", "${2:value}");${3}
 | |
| snippet ci_form_upload
 | |
| 	form_upload("${1:name}", "${2:value}");${3}
 | |
| snippet ci_form_textarea
 | |
| 	form_textarea("${1:name}", "${2:value}");${3}
 | |
| snippet ci_form_dropdown
 | |
| 	form_dropdown("${1:name}", $${2:options}, $${3:selected);${4}
 | |
| snippet ci_form_checkbox
 | |
| 	form_checkbox("${1:name}", "${2:value}");${3}
 | |
| snippet ci_form_radio
 | |
| 	form_radio("${1:name}", "${2:value}");${3}
 | |
| snippet ci_form_submit
 | |
| 	form_submit("${1:name}", "${2:value}");${3}
 | |
| snippet ci_form_reset
 | |
| 	form_reset("${1:name}", "${2:value}");${3}
 | |
| snippet ci_form_button
 | |
| 	form_button("${1:name}", "${2:value}");${3}
 | |
| snippet ci_form_label
 | |
| 	form_label("${1:label text}", "${2:id}");${3}
 | |
| snippet ci_form_close
 | |
| 	form_close();${1}
 | |
| snippet ci_validation_errors
 | |
| 	validation_errors();${1}
 | |
| # Session Class snippets
 | |
| snippet ci_session_userdata
 | |
| 	$this->session->userdata("${1:item}");${2}
 | |
| snippet ci_session_set_userdata
 | |
| 	$this->session->set_userdata($${1:array});${2}
 | |
| snippet ci_session_flashdata
 | |
| 	$this->session->flashdata("${1:item}");${2}
 | |
| snippet ci_session_set_flashdata
 | |
| 	$this->session->set_flashdata("${1:item}", "${2:value}");${3}
 | 
