在cakePHP中,将验证语句放入控制器时,如何实现日期验证?我可以在第一个验证声明后添加第二个if语句吗?我不确定如果系统日期等于或等于到期日期,你如何确认它
if($this->Invoice->validates(array('fieldList'=>array('Relationship.partyone','Relationship.active'))))
{
$this->Invoice->create();
if ($this->Invoice->saveAll($this->request->data,array('validate'=>false)))
{
$this->Session->setFlash('The invoice has been saved');
答案 0 :(得分:1)
您可能需要自定义验证日期日期比较
在模型中
var $validate = array(
'date' => array(
'rule' => array('datevalidation', 'systemDate' ),
'message' => 'Current Date and System Date is mismatched'
)
);
function datevalidation( $field=array(), $compare_field=null )
{
if ($field['date'] > $compare_field)
return TRUE;
else return FALSE;
}
在控制器中
if($this->Invoice->validates(array('fieldList'=>array('Relationship.partyone','Relationship.active',Relationship.date))))