I have a CActiveRecord in which I have a unique field and I want to use that unique validator in the form model. Is this simply possible by adding a rule to the rules() in the CFormModel instance or should I define a method in the specific CFormModel or CActiveRecord and add that as a validator?
I’ve tried searching without success. Anyone ever tried this or know pointers to documentation?
You can simply add ‘unique’ rule to the rules method of your CFormModel. But you have to specify ‘className’ property explicitly when you want to use CUniqueValidator in a CFormModel (or in other CAcitveRecord).
It took me some to comprehend all possibilities but now that I know my way around a bit; awesome!!
I only find the documentation a bit on the weak side, you need to be aware of the ‘greater picture’ to understand things and see possibilities to let Yii do the work for you, but once you do… How did I ever do without?