화면에서 날짜입력을 구현해야 하는 경우가 많습니다.
최근에는 대부분 jQueryui DataPicker를 많이 쓰더군요~
참 편리해졌습니다.
YII의 경우는 모든 Validation을 Model에서 수행하게 됩니다.
대부분은 튜토리얼에 잘 정리되어있으나, 날짜 Validation 에 대한 건 많이 없어서
알려드립니다.
Model 의 rule 메서드로 이동합니다.
아래와 같이 type, 날짜 포멧과 message를 지정해줍니다.
아래와 같이 지정해주면 편리하게 Validation 할 수 있습니다.
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('USER_ID, IDX, DATE', 'required'),
array('IDX', 'numerical', 'integerOnly'=>true),
array('DATE', 'type', 'type' => 'date', 'message' => '{attribute}는 날짜 형식이 아닙니다.', 'dateFormat' => 'yyyy-mm-dd'),
array('LEAVETIME', 'type', 'type' => 'date', 'message' => '{attribute}은 시간 형식이 아닙니다.', 'dateFormat' => 'hh:mm'),
.......................
);
}