yii规则从数据库验证

I have a table of places each place has:

id|name|work_start|work_end 

The user can make a reservation in a certain place and he needs to input the time he wants it. I want to validate if the time is between work's start and work's end.

I'm a new to yii, I can do it easily in the controller but I want the best practice to do it. Can I put a rule in the ActiveRecord or is there any other method to do it?

You could use a couple of compare rules

['fromDate', 'compare', 'your_date_attribute' => 'toDate', 'operator' => '<', 
             'enableClientValidation' => false],
['toDate', 'compare', 'your_date_attribute' => 'toDate', 'operator' => '>', 
             'enableClientValidation' => false],

see this for some suggestion http://www.yiiframework.com/doc-2.0/guide-tutorial-core-validators.html