我试图检查杂货店的有效日期(结束日期应该在开始日期之后)但是下面的代码不起作用它仍然保存无效日期,任何人都可以帮忙吗?
$crud->set_rules('cardEnd','End Date','callback_valid_dates[cardEnd,cardStart]'); //dEnd before dStart
$output = $this->grocery_crud->render();
$output = $crud->render();
$this->cards_output($output);
}
function cards_output($output = null)
{
$this->load->view('cards_view.php', $output);
}
public function check_dates($dEnd, $dStart)
{
$var1 = explode('/', $this->input->post('dStart'));
$var2 = explode('/', $this->input->post('dEnd'));
$dEnd = join('-', $var2);
if ($dEnd >= $dStart)
{
return TRUE;
}
else
{
$this->form_validation->set_message('valid_date', "invalid date range end date must be after the start date ");
return FALSE;
}
}
答案 0 :(得分:1)
将check_dates()
函数替换为此 -
public function check_dates($dEnd, $dStart)
{
$var1 = strtotime($this->input->post('dStart'));
$var2 = strtotime($this->input->post('dEnd'));
if ($var2 >= $var1)
{
return TRUE;
}
else
{
$this->form_validation->set_message('valid_date', "invalid date range end date must be after the start date ");
return FALSE;
}
}