Skip to content

Instantly share code, notes, and snippets.

@veganista
veganista / UsersControllerTest.php
Created May 4, 2012 20:37
CakePHP Controller Tetsing
<?php
/* Users Test cases generated on: 2012-03-13 19:59:39 : 1331668779*/
App::uses('UsersController', 'Controller');
/**
* TestUsersController *
*/
class TestUsersController extends UsersController {
/**
* Auto render
class User extends AppModel {
public $name = 'User';
public $belongsTo = array(
'FriendOne' => array(
'className' => 'Friend',
'foreignKey' => 'friend_1_id',
),
'FriendTwo' => array(
'className' => 'Friend',
'foreignKey' => 'friend_2_id',
//set error handling up
libxml_use_internal_errors(true);
//path to the validation file
$validationSchema = dirname(__FILE__).DS.'docs'.DS.'tff'.DS.'XMLImport.xsd';
//set up a new document to work with
$doc = new DOMDocument();
$doc->formatOutput = true;
$doc->preserveWhiteSpace = false;
//current find results look like this
array
0 =>
array
0 =>
array
'year' => string '2012' (length=4)
'month' => string 'May' (length=3)
'count' => string '5' (length=1)
1 =>
$dob = explode('-', $applicationData['Applicant']['date_of_birth']);
$dobDayArray = explode(' ', $dob[2]);
$dobDay = $dobDayArray[0];
$dobMonth = $dob[1];
$dobYear = $dob[0];
echo $this->Form->input('Applicant.date_of_birth', array(
'type' => 'date',
'dateFormat' => 'DMY',
/*
* If this doenst work then try the below
*/
echo $this->Form->input('Applicant.date_of_birth', array(
'type' => 'date',
'dateFormat' => 'DMY',
'minYear' => date('Y') - 110,
'maxYear' => date('Y')- 18,
)
);
public function beforeSave(Model $model, array $options = array()){
var_dump($model->data['User']);
//array (size=4)
// 'id' => string '66' (length=2)
// 'first_name' => string 'new first name' (length=14)
// 'last_name' => string 'new last name' (length=13)
// 'email' => string 'liam@email.com' (length=14)
$x = $model->find('first', array('conditions' => array($model->alias . '.' .$model->primaryKey => $model->id), 'contain' => 'User'));
@veganista
veganista / gist:5764323
Created June 12, 2013 10:42
Batch resize images from CLI with image magick
convert *.jpg -resize 236 -set filename:filename '%t-%wx%h' 'resized/%[filename:filename].jpg'
@veganista
veganista / example.php
Created September 26, 2013 10:28
Getting the URL of category in OpenCart.
<?php echo $this->url->link('product/category', 'path=96'); ?>
// http://example.com/category-three/
<?php echo $this->url->link('product/category', 'path=63_78'); ?>
// http://example.com/category-one/category-two/
<?php echo $this->url->link('product/category', 'path=63_78_96'); ?>
@veganista
veganista / functions.php
Created May 9, 2016 09:06
Disable author pages in WordPress
/**
* Disable author pages
*/
add_action( 'template_redirect', function(){
global $wp_query;
if ( is_author() && !is_404() ) {
$wp_query->set_404();
status_header( 404 );
nocache_headers();
}