0

在 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'); 
4

1 回答 1

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))))
于 2012-05-27T08:05:37.197 回答