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:Share on twitter

Twitter

Share on reddit

Reddit

Share on linkedin

Linkedin

Share on facebook

Facebook

Share on email

Email