public
Last active

CodeIgniter PHP snippets for the VIM plugin SnipMate

  • Download Gist
php.snippets
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
# SnipMate is required to use snippets
# Download SnipMate: http://www.vim.org/scripts/script.php?script_id=2540
# Put this file in ~/.vim/snippets/ then restart vim
# This snippet file includes many useful snippets for CodeIgniter. Please feel free to fork and contribute!
snippet php
<?php
${1}
?>
snippet ec
echo "${1:string}"${2};
snippet inc
include '${1:file}';${2}
snippet inc1
include_once '${1:file}';${2}
snippet req
require '${1:file}';${2}
snippet req1
require_once '${1:file}';${2}
# $GLOBALS['...']
snippet globals
$GLOBALS['${1:variable}']${2: = }${3:something}${4:;}${5}
snippet $_ COOKIE['...']
$_COOKIE['${1:variable}']${2}
snippet $_ ENV['...']
$_ENV['${1:variable}']${2}
snippet $_ FILES['...']
$_FILES['${1:variable}']${2}
snippet $_ Get['...']
$_GET['${1:variable}']${2}
snippet $_ POST['...']
$_POST['${1:variable}']${2}
snippet $_ REQUEST['...']
$_REQUEST['${1:variable}']${2}
snippet $_ SERVER['...']
$_SERVER['${1:variable}']${2}
snippet $_ SESSION['...']
$_SESSION['${1:variable}']${2}
# Start Docblock
snippet /*
/**
* ${1}
**/
# Class - post doc
snippet doc_cp
/**
* ${1:undocumented class}
*
* @package ${2:default}
* @author ${3:`g:snips_author`}
**/${4}
# Class Variable - post doc
snippet doc_vp
/**
* ${1:undocumented class variable}
*
* @var ${2:string}
**/${3}
# Class Variable
snippet doc_v
/**
* ${3:undocumented class variable}
*
* @var ${4:string}
**/
${1:var} $${2};${5}
# Class
snippet doc_c
/**
* ${3:undocumented class}
*
* @packaged ${4:default}
* @author ${5:`g:snips_author`}
**/
${1:}class ${2:}
{${6}
} // END $1class $2
# Constant Definition - post doc
snippet doc_dp
/**
* ${1:undocumented constant}
**/${2}
# Constant Definition
snippet doc_d
/**
* ${3:undocumented constant}
**/
define(${1}, ${2});${4}
# Function - post doc
snippet doc_fp
/**
* ${1:undocumented function}
*
* @return ${2:void}
* @author ${3:`g:snips_author`}
**/${4}
# Function signature
snippet doc_s
/**
* ${4:undocumented function}
*
* @return ${5:void}
* @author ${6:`g:snips_author`}
**/
${1}function ${2}(${3});${7}
# Function
snippet doc_f
/**
* ${4:undocumented function}
*
* @return ${5:void}
* @author ${6:`g:snips_author`}
**/
${1}function ${2}(${3})
{${7}
}
# Header
snippet doc_h
/**
* ${1}
*
* @author ${2:`g:snips_author`}
* @version ${3:$Id$}
* @copyright ${4:$2}, `strftime('%d %B, %Y')`
* @package ${5:default}
**/
/**
* Define DocBlock
*//
# Interface
snippet doc_i
/**
* ${2:undocumented class}
*
* @package ${3:default}
* @author ${4:`g:snips_author`}
**/
interface ${1:}
{${5}
} // END interface $1
# class ...
snippet class
/**
* ${1}
**/
class ${2:ClassName}
{
${3}
function ${4:__construct}(${5:argument})
{
${6:// code...}
}
}
# define(...)
snippet def
define('${1}'${2});${3}
# defined(...)
snippet def?
${1}defined('${2}')${3}
snippet wh
while (${1:/* condition */}) {
${2:// code...}
}
# do ... while
snippet do
do {
${2:// code... }
} while (${1:/* condition */});
snippet if
if (${1:/* condition */}) {
${2:// code...}
}
snippet ife
if (${1:/* condition */}) {
${2:// code...}
} else {
${3:// code...}
}
${4}
snippet else
else {
${1:// code...}
}
snippet elseif
elseif (${1:/* condition */}) {
${2:// code...}
}
# Tertiary conditional
snippet t
$${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b};${5}
snippet switch
switch ($${1:variable}) {
case '${2:value}':
${3:// code...}
break;
${5}
default:
${4:// code...}
break;
}
snippet case
case '${1:value}':
${2:// code...}
break;${3}
snippet for
for ($${2:i} = 0; $$2 < ${1:count}; $$2${3:++}) {
${4: // code...}
}
snippet foreach
foreach ($${1:variable} as $${2:key}) {
${3:// code...}
}
snippet fun
${1:public }function ${2:FunctionName}(${3})
{
${4:// code...}
}
# $... = array (...)
snippet array
$${1:arrayName} = array(
'${2}' => ${3},
);${4}
##### CodeIgniter Snippets #####
# Generic $this->
snippet this
$this->${1:model/controller}->${2:method}(${3:array});${4}
# New Model Class
snippet classm
<?php
/*
* ${1:Describe the model's purpose}
*/
class ${2:model name} extends CI_Model
{
function __construct()
{
parent::__construct();
}
${3:// Code...}
}
# New Controller Class
snippet classc
<?php
/*
* ${1:Describe the controller's purpose}
*/
class ${2:controller name} extends CI_Controller
{
function __construct()
{
parent::__construct();
}
${3:// Code...}
}
# Form Validation Rules
snippet formrule
$this->form_validation->set_rules('${1:field name}','${2:human name}', '${3:rules}');${4}
# Data array - $data['key']
snippet darr
$data['${1:arrayName}'] = array(
'${2}' => ${3},${4}
);
# Additional array data
snippet arrv
'${1}' => ${2},${3}
# Load view template
snippet loadtemp
$data['main_content'] = '${1:view}';
$this->load->view('includes/template', $data);${2}
##### Common Functions #####
# Form validation run == FALSE
snippet funform
function ${1:function}()
{
${2:rules}
if($this->form_validation_run() == FALSE)
{
${3:form data arrays}
}
else
{
${4:success view}
}
}
# Return If
snippet returnif
if ($q->num_rows() > 0)
{
$${1:array} = $q->row_array();
return $${1:array};
}
else
{
return FALSE;
}
##### Form Helper #####
# Validation Errors
snippet valerr
<?php echo validation_errors(); ?>${1}
# Form Open
snippet formo
<?php echo form_open('${1:form controller}'); ?>${2}
# Form Close
snippet formc
<?php echo form_close(); ?>${1}
## Form Fields ##
# Hidden
snippet fhidden
<?php echo form_hidden('${1:name}', ${2:array}); ?>${3}
# Input
snippet finput
<?php echo form_input('${1:array}', set_value('${2:name}')); ?>${3}
# Password
snippet fpass
<?php echo form_password('${1:array}', set_value('${2:name}')); ?>${3}
# Upload
snippet fupload
<?php echo form_upload('${1:array}', set_value('${2:name}')); ?>${3}
# Text area
snippet ftext
<?php echo form_textarea('${1:array}', set_value('${2:name}')); ?>${3}
# Drop-down
snippet fdrop
<?php echo form_dropdown('${1:name}',${2:array}, $this->input->post('${1}')); ?>${3}
# Checkbox
snippet fcheck
<?php echo form_checkbox($${1:array}['${2:key}'], '', set_checkbox('${1}[]', '${2}')); ?>${3}
# Radio button
snippet fradio
<?php echo form_radio($${1:array}['${2:key}'], '', set_radio('${1}[]', '${2}')); ?>${3}
# Form submit
snippet fsubmit
<?php echo form_submit('${1:name}', '${2:value}'); ?>${3}
# Form reset
snippet freset
<?php echo form_reset('${1:name}', '${2:value}'); ?>${3}
# Fieldset open
snippet fieldo
<?php form_fieldset('${1:label}', '${2:array}'); ?>${3}
# Fieldset close
snippet fieldc
<?php form_fieldset_close(); ?>${1}
##### HTML Snippets #####
# <br>
snippet r
<br`Close()[1:]`>
# Div with class
snippet div
<div id="${1:name}" class="${2}">
${3}
</div>
# Ordered list
snippet ol
<ol id="${1}">
${2}
</ol>
# Unordered list
snippet ul
<ul id="${1}">
${2}
</ul>
# List Item
snippet li
<li>${1}</li>${2}
##### PHP/HTML Shorthand #####
# PHP Foreach
snippet sforeach
<?php foreach ($${1:array} as $${2:key}) : ?>
${3:// code...}
<?php endforeach; ?>
##### Database Class/Active Record #####
# Get query
snippet dbget
$q = $this->db->get('${1:table}');${2}
# Get_where query
snippet dbgetwhere
$q = $this->db->get_where('${1:table}', array('${2:field}' => $${3:input}));${4}
# Select
snippet dbselect
$this->db->select('${1:fields}');${2}
# Where
snippet dbwhere
$this->db->where('${1:field}', $${2:input});${3}
# Insert
snippet dbinsert
$this->db->insert('${1:table}', $${2:array});${3}
# Update
snippet dbupdate
$this->db->update('${1:table}', $${2:array});${3}
# Delete
snippet dbdelete
$this->db->delete('${1:table}', $${2:array});${3}
##### URL Helper #####
# Site URL
snippet surl
<?php echo site_url("${1:segments}"); ?>${2}
# Base URL
snippet burl
<?php echo base_url(); ?>${1}
# Current URL
snippet curl
<?php echo current_url(); ?>${1}
# Anchor
snippet anchor
<?php echo anchor('${1:segments}', '${2:text}', '${3:attributes}'); ?>${4}
# Safe Mailto
snippet mailto
<?php echo safe_mailto('${1:email}', '${2:text}'); ?>${3}

Check out my edits. I added a few classes, and reworked the new controller method.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.