I'm just wondering if there is way to run a validation function from your rules method where you don't need to pass in any parameters to it?
So normally you would pass in the attribute name for the property, but say you know what properties you want to use such as $this->foo and $this->bar.
So a normal custom inline validator would be done like this:
['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".');
}
}
Like I'm currently doing this:
['username', 'regAvailable', 'params' => ['email' => 'email']],
public function regAvailable($attribute, $params) {
$username = $this->{$attribute};
$email = $this->{$params['email']};
}
Sure, it does the job. But seems a bit overkill when I can just do:
public function regAvailable($attribute, $params) {
$username = $this->username;
$email = $this->email;
}
Sure, I can still do it this way, but then I kinda feel like the code wouldn't be very "clean" by having those unused parameters there; I would prefer to have it like this:
public function regAvailable() {
$username = $this->username;
$email = $this->email;
}
Is there anyway do do something like that? If so, how?