I have this model
use Phalcon\Mvc\Model,
Phalcon\Mvc\Model\Validator\PresenceOf;
class Posts extends Model{
public $id;
public $title;
public $content;
public $createDate;
public $lastEditDate;
public $status;
public $slug;
public $author_id;
public function initialize(){
$this->belongsTo('author_id', '\App\Models\Users', 'id', array(
'alias' => 'author'
));
$this->hasMany('id', '\App\Models\PostsComments', 'post_id', array(
'alias' => 'comments'
));
}
public function validation(){
//title
$this->validate(new PresenceOf(array(
'field' => 'title',
'message' => 'Un article doit avoir un titre.'
)));
$this->validate(new Model\Validator\StringLength(array(
'field' => 'title',
'min' => 3,
'max' => 255,
'messageMinimum' => "Le titre de l'article est trés cour, il faut au moins 3 caractéres.",
'messageMaximum' => "Le titre de l'article est trés long, pas plus que 255."
)));
//content
$this->validate(new Model\Validator\PresenceOf(array(
'field' => 'content',
'message' => 'Un article sans contenu ?!.',
)));
return !$this->validationHasFailed();
}
}
The Validation function looks ok but when I try to add a post with wrong information, the errors messages still the default Phalcon messages, and whene I add a title with 2 chars length (lower than the min of StringLength), no error detected...