Where To Put Validation Not Related To Model Attributes?

Hello!

I have a question about design of AR model validation.

Validations related to model’s attributes goes to the rules() method, but where is the best place for validations not related to these attributes?

Let’s see an example: I have a model: Room (chatroom) with attributes: name, password, etc.

These attributes has their own validation rules, but I need an extra validation, because to create a new room, the user needs some credits.

Where is the best place in the code to check, if the user have credits needed for room creation?

Thank you!

You could create custom validator for this purpose - and place it directly as method of your Room model or in external file.

Here are code examples - http://www.yiiframework.com/wiki/168/create-your-own-validation-rule/

Thanks, i use this approach, but now i don’t go to validate a model attribute.