如何在phalconphp中的自定义验证器中运行查询

时间:2014-05-23 09:40:05

标签: php validation phalcon

我正在尝试制作自定义验证程序,以检查电子邮件是否已被提交。为此我需要在我的自定义验证器中执行查询,我该怎么做?

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...     
    }

}

1 个答案:

答案 0 :(得分:1)

如果将myTable映射到模型,您可以:

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'");
        ...
    }
}