Skip to content

Instantly share code, notes, and snippets.

@tareko
Created October 20, 2012 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tareko/3922881 to your computer and use it in GitHub Desktop.
Save tareko/3922881 to your computer and use it in GitHub Desktop.
BillingsItem model
<?php
App::uses('AppModel', 'Model');
/**
* BillingsItem Model
*
* @property Billings $Billings
*/
class BillingsItem extends AppModel {
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'service_date' => array(
'date' => array(
'rule' => array('date'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Billing' => array(
'className' => 'Billing',
'foreignKey' => 'billing_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
public function beforeValidate($options = array()) {
if (!empty($this->data['BillingsItem']['service_date'])) {
$this->data['BillingsItem']['service_date'] = $this->dateFormatBeforeSave($this->data['BillingsItem']['service_date']);
}
return true;
}
public function dateFormatBeforeSave($dateString) {
return date('Y-m-d', strtotime($dateString));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment