I'm aware you can validate a single attribute using an inline validator such as:
['country', 'validateCountry']
public function validateCountry($attribute, $params)
{
if (!in_array($this->$attribute, ['USA', 'Web'])) {
$this->addError($attribute, 'The country must be either "USA" or "Web".');
}
}
But how do I go about passing in multiple attributes into the validator? ...or should I just reference them via $this within the validator?
['country', 'validateCountry']basically states that validateCountry is applied to country, if you want to apply the validator function to other attribute just add['secondAttribute', 'validateCountry']and the validator would automatically apply the function for bothcountryandsecondAttributecountryattribute which is$this->country. However I need to make a custom validator function to check theusernameandemailattributes against the database; I would prefer to pass them BOTH to a single validator rather than separately so I can just run the single query.