为什么自定义错误显示错误的日期?

时间:2014-07-16 15:35:21

标签: php yii

错误日期显示错误。模型(BookingRoom)在表格输入表单上的开始日期和结束日期运行此自定义规则,以检查重叠的日期范围。我能做错什么?

public function notOverlap()
{                      
    $startDateThis = new DateTime($this->startDate);                        
    $endDateThis = new DateTime($this->endDate); 
    $criteria = new CDbCriteria;

    $criteria->condition = "(id !='".$this->id."' AND bookingId ='".$this->bookingId."')";

    $items = BookingRoom::model()->findAll($criteria);



            foreach ($items as $item){                    

                $startDateItem = new DateTime($item->startDate);                    
                $endDateItem = new DateTime($item->endDate);                    


                   if ($startDateItem <= $endDateThis && $startDateThis <= $endDateItem)             
                      {                
                        $this->addError('startDate', 'Room already taken!');
                        $this->addError('endDate', 'Room already taken!');
                      }                    
            } 
}

0 个答案:

没有答案