Skip to content

Instantly share code, notes, and snippets.

View jaredhoyt's full-sized avatar

Jared Hoyt jaredhoyt

View GitHub Profile
@jaredhoyt
jaredhoyt / gist:824458
Created February 13, 2011 04:49
Example Permissionable usage
<?php
class Account extends AppModel {
var $actsAs = array('Permissionable');
var $hasMany = array(
'User' => array('dependent' => true)
);
function permissions($user) {
if ($user['Role']['accounts'] != 'owner') {
return false;
@jaredhoyt
jaredhoyt / gist:822728
Created February 11, 2011 17:45
Example password validation
<?php
class User extends AppModel {
var $validate = array(
'first_name' => array('rule' => 'notEmpty', 'message' => 'Please enter a first name.'),
'last_name' => array('rule' => 'notEmpty', 'message' => 'Please enter a last name.'),
'phone' => array('rule' => array('phone', null, 'us'), 'allowEmpty' => true, 'message' => 'Please enter a valid phone number.'),
'email' => array(
'email' => array('rule' => array('email', true), 'message' => 'Please use a valid email address.'),
'isUnique' => array('rule' => 'isUnique', 'message' => 'This email address is already being used.')
),
@jaredhoyt
jaredhoyt / gist:820739
Created February 10, 2011 15:48
PdfView for tcpdf
<?php
App::import('Vendor', 'tcPDF', array('file' => 'tcpdf' . DS . 'tcpdf.php'));
class CustomPDF extends TCPDF {
public function Footer() {
}
public function Header() {
}
}
@jaredhoyt
jaredhoyt / gist:797617
Created January 26, 2011 22:23
Custom pagination with results per page
results = {
ajaxRequest : null,
ajaxLoader : '<div class="ajax_loader"><div class="overlay"></div><div class="message">Loading...</div></div>',
displayLoader : function(container){
container = container || $('div.records:first');
if ($(container).find('div.ajax_loader').length) {
return;
}
@jaredhoyt
jaredhoyt / app_model.php
Created January 26, 2011 21:35
Polymorphic - example usage
<?php
class AppModel extends Model {
function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
if (isset($this->hasMany['Note'])) {
$this->hasMany['Note']['conditions']['Note.class'] = $this->name;
$this->hasMany['Note']['foreignKey'] = 'foreign_id';
}
}
}
@jaredhoyt
jaredhoyt / gist:793288
Created January 24, 2011 14:31
Javascript table row clone example
<table id="prejam_vendors">
<thead>
<tr>
<th class="text_left">Vendor Name</th>
<th class="text_left">Quote Date</th>
<th class="text_left">Quote #</th>
<th class="text_left">Description</th>
<th class="text_left">Discount</th>
<th class="text_left">Price Book</th>
<th class="text_left">Quote Expiration Date</th>
@jaredhoyt
jaredhoyt / build_acl.php
Created January 21, 2011 15:13
BuildAclShell
<?php
App::import('Core', 'Controller');
class BuildAclShell extends Shell {
function main() {
$log = array();
App::import('Component', 'Acl');
$acl =& new AclComponent(null);
$aco =& $acl->Aco;
$root = $aco->node('controllers');
@jaredhoyt
jaredhoyt / stateful.php
Created January 19, 2011 16:06
StatefulComponent
<?php
class StatefulComponent extends Object {
var $components = array('Session');
function initialize(&$controller, $settings = array()) {
$this->controller =& $controller;
$this->_set($settings);
}
function startup() {
@jaredhoyt
jaredhoyt / hosts
Created January 13, 2011 22:12
Example Apache setup (with SSL)
# Secure local IPs:
#
# 127.0.0.2 - www.example.dev
#
127.0.0.1 localhost
# example.com
127.0.0.2 www.example.dev
<?php
class Contact extends AppModel {
var $actsAs = array('Acl' => array('requester'));
var $belongsTo = array(
'Account',
'Role',
'Supervisor' => array(
'className' => 'Contact',
'foreignKey' => 'supervisor_id'
)