Skip to content

Instantly share code, notes, and snippets.

<?php
$cache = array
(
15 => array('id' => 15, 'title' => 'United States', 'shortname' => 'USA');
);
$data = Country_Model::cache($title, 'title');
$data is now array('id' => 15, 'title' => 'United States', 'shortname' => 'USA');
<?php
class Model_Page extends ORM {
protected $belongs_to = array('menu', 'user');
protected $sorting = array('created' => 'asc');
public function __get($column)
{
var jump = $(this);
var size = jump.height();
var _min = parseInt(jump.offset().top);
var _max = jump.parent().parent().height();
var _win = $(window);
// Callback for scrolling
var callback = function()
{
// Get the current scroll offset
<?php
public function find_all_by_role($role)
{
return $this
->join('roles_users', 'users.id', 'roles_users.user_id')
->join('roles', 'roles_users.role_id', 'roles.id')
->where('roles.name', $role)
->find_all();
}
<?php defined('SYSPATH') or die('No direct script access.');
class User_Model extends ORM {
protected $ignored_columns = array('birthday_day', 'birthday_month', 'birthday_year');
public function validate(array & $array, $save = FALSE)
{
$array = Validation::factory($array)
->pre_filter('trim')
<?php
public function create()
{
$this->template->content = View::factory('admin/users/edit')
->bind('roles', $roles)
->bind('post', $post)
->bind('errors', $errors)
->bind('cancel', $return)
->bind('delete', $delete);
<?php
public function validate(array & $array, $save = FALSE)
{
$array = Validation::factory($array)
->pre_filter('trim')
->add_rules('email', 'required', 'length[4,127]', 'valid::email', array($this, 'check_email'))
->add_rules('password', 'length[5,127]')
->add_rules('password_confirm', 'matches[password]')
->add_rules('roles', 'is_array');
<?php
public function find_all_by_country($country)
{
return $this
->select('DISTINCT categories.*')
->join('categories_products', 'categories_products.category_id', 'categories.id')
->join('products', 'products.id', 'categories_products.product_id')
->join('product_skus', 'product_skus.product_id', 'products.id')
->join('countries_product_skus', 'countries_product_skus.product_sku_id', 'product_skus.id')
<?php
// Standard QUery
$query = DB::query('SELECT * FROM users WHERE username = :username LIMIT 1');
$query->set(':username', 'shadowhand');
$result = $query->execute();
// Builder Query
$query = DB::select('*')->from('users')->where('username', '=', ':username')->limit(1);
$query->set(':username', 'shadowhand')
<?php
public function find_unique($value)
{
$sql = 'SELECT * FROM users WHERE username = :value OR email = :value LIMIT 1';
$query = DB::select($sql);
$query->execute(array(':value' => $value));
}