我正在尝试制作自定义验证程序,以检查电子邮件是否已被提交。为此我需要在我的自定义验证器中执行查询,我该怎么做?
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...
}
}
答案 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'");
...
}
}