Pars
Pars

Reputation: 5272

how to run query inside a custom validator in phalconphp

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

Answers (1)

cvsguimaraes
cvsguimaraes

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

Related Questions