Created
October 20, 2012 10:17
-
-
Save tareko/3922881 to your computer and use it in GitHub Desktop.
BillingsItem model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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