【发布时间】:2015-09-28 07:06:29
【问题描述】:
如何使用我创建的验证器?
我在 models/Posts.php 中有模型
<?php
class Posts extends \Phalcon\Mvc\Model
{
public function validation()
{
$this->validation(new OtherThanActive([
'field' => 'title'
]));
return ($this->validationHasFailed() != true);
}
}
?>
我在 /app/validators/PostsValidators.php 中创建了验证器 (我在配置中添加并加载此目录)
验证器代码:
<?php
class OtherThanActive extends Validator implements ValidatorInterface
{
public function validate(Validation $validator, $attr)
{
$postId = $this->getOption('postId');
$field = $this->getOption('field');
$active = \Posts::findFirst($attr['postId'])->users->active;
if($attr['postTitle'] == $active)
{
$validator->appendMessage(new Message('Here is error message...'));
return false;
}
return true;
}
}
?>
当我想在模型中使用我的 walidator 时,我遇到了找不到 OtherThanActive 类的错误。
我们如何在 phalcon 中包含自己的验证器???
谢谢
【问题讨论】:
标签: php forms validation phalcon