Here’s an example of how to use the Yii2 compare validator.

The rules go in your model e.g. app/models/Participant.php. In this example, I’m ensuring that the participant_id and the invited_by id are not the same. I don’t want someone to be able to invite themselves.

[php]
public function rules()
{
return [
[‘participant_id’, ‘compare’,’compareAttribute’=>’invited_by’,’operator’=>’!=’,’message’=>’You cannot invite yourself.’],
];
}
[/php]

Support this site, share this page:Tweet about this on Twitter

Twitter

Share on Reddit

Reddit

Share on LinkedIn

Linkedin

Share on Facebook

Facebook

Email this to someone

email