Skip to content

Instantly share code, notes, and snippets.

View McGaiser's full-sized avatar

Michael Gaiser McGaiser

View GitHub Profile
@McGaiser
McGaiser / gist:79ab717181d87bee7fbb
Created September 18, 2014 05:35
A Role Record.
object(Cake\ORM\Query) {
'sql' => 'SELECT Roles.id AS `Roles__id`, Roles.parent_id AS `Roles__parent_id`, Roles.lft AS `Roles__lft`, Roles.rght AS `Roles__rght`, Roles.name AS `Roles__name`, Roles.description AS `Roles__description`, Roles.created AS `Roles__created`, Roles.updated AS `Roles__updated`, Parents.id AS `Parents__id`, Parents.parent_id AS `Parents__parent_id`, Parents.lft AS `Parents__lft`, Parents.rght AS `Parents__rght`, Parents.name AS `Parents__name`, Parents.description AS `Parents__description`, Parents.created AS `Parents__created`, Parents.updated AS `Parents__updated` FROM roles AS Roles LEFT JOIN roles Parents ON Parents.id = (Roles.parent_id)',
'params' => [],
'defaultTypes' => [
'Roles.id' => 'integer',
'id' => 'integer',
'Roles.parent_id' => 'integer',
'parent_id' => 'integer',
'Roles.lft' => 'integer',
@McGaiser
McGaiser / gist:edf27674ca3632414514
Created September 25, 2014 19:21
get_class_methods results
array (size=59)
0 => string 'initialize' (length=10)
1 => string 'validationDefault' (length=17)
2 => string 'initializeDb' (length=12)
3 => string '__construct' (length=11)
4 => string 'defaultConnectionName' (length=21)
5 => string 'table' (length=5)
6 => string 'alias' (length=5)
7 => string 'connection' (length=10)
8 => string 'schema' (length=6)
@McGaiser
McGaiser / gist:9ee33ff9e46dd1fb491c
Created September 25, 2014 19:45
getActions function
// src/Model/Table/ResourcesTable.php
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\Validation\Validator;
use ReflectionClass;
class ResourcesTable extends AppTable {
@McGaiser
McGaiser / gist:dca33db8faff47af1b3f
Created October 6, 2014 23:01
AssignmentTable Validator
public function validationDefault(Validator $validator) {
return $validator
->validatePresence('role_id')
->notEmpty('role_id', 'A role is required')
->add('role_id', [
'unique' => [
'rule' => function($value, $context){
//debug($context);
return $context['data']['isUnique'];
@McGaiser
McGaiser / gist:c605780d54b62c78abbb
Last active August 29, 2015 14:07
New Widget issues
//This is my autocomplete widget
<?php
namespace App\View\Widget;
use Cake\View\Widget\WidgetInterface;
use Cake\View\Form\ContextInterface;
class Autocomplete implements WidgetInterface {
@McGaiser
McGaiser / PrestigeLogController.php
Created December 18, 2015 11:40
Issues saving stuff
Controller:
public function editPrestige($id=null){
$prestigeLog = $this->PrestigeLogs->find()
->contain([
'Members.Domains',
'PrestigeLogsItems'=> function ($q){
public function editPrestige($id=null){
$prestigeLog = $this->PrestigeLogs->get($id,
['contain'=>[
'Members.Domains',
'PrestigeLogsItems'=> function ($q){
return $q->where(['approved_id IS NULL']);
}
]]);
//From /cam-website/config/bootstrap.php
Plugin::load('Incentives', ['bootstrap' => false, 'routes' => true]);
//From /cam-website/config/routes.php
<?php
/**
<?php
use Cake\Routing\Router;
Router::scope('/', function($routes) {
$routes->connect('/PrestigeLogs', ['controller' => 'PrestigeLogs', 'plugin'=>'Incentives']);
}
);
//MembershipClassesTable.php
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Cake\Model\Behavior\TreeBehavior;
class MembershipClassesTable extends AppTable {
public function initialize(array $config){