Reputation: 5272
Im trying to make a custom validator to check if an email is already submited or not. for this I need to execute query in my custom validator, How can I do that?
use Phalcon\Validation\Validator,
Phalcon\Validation\ValidatorInterface,
Phalcon\Validation\Message;
Class Unique extends Validator implements ValidatorInterface {
public function validate($validator, $attribute) {
// how to execute "SELECT * FROM myTable" here...
}
}
Upvotes: 0
Views: 127
Reputation: 13250
If myTable
is mapped to a Model you can just:
use Phalcon\Validation\Validator;
use Phalcon\Validation\ValidatorInterface;
use Phalcon\Validation\Message;
use MyTable;
class Unique extends Validator implements ValidatorInterface
{
public function validate($validator, $attribute)
{
$result = MyTable::findFirst("id = 1 AND status = 'sent'");
...
}
}
Upvotes: 1