public
Created

BillingsItem model

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
<?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));
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.