我使用Codeigniter,有两个变量event_start_time
和event_end_time
。我需要检查开始时间是否大于结束时间。
如何使用Codeigniter中的表单验证库来验证它?
$this->form_validation->set_rules('event_start_time', 'Starttid', 'required|strip_tags|trim');
$this->form_validation->set_rules('event_end_time', 'Sluttid', 'required|strip_tags|trim');
2条答案
按热度按时间cygmwpex1#
Hi CI中没有此选项。
您必须简单地使用比较运算符,如下所示:
if($event_start_time > $event_end_time){ /.../ }
llmtgqce2#
有几种方法可以实现这一点,但这是我首先要尝试的(代码未经测试)。
假设这是CodeIgniter 3
1)在/application/config/validation/validate. php中创建以下配置文件
2)在/application/models/validation/time_logic. php中创建验证模型
3)在您的控制器、模型或任何您要验证post的地方,加载并应用验证规则,而不是指定它们是如何进行的。