Having a super-difficult time getting basic validation to happen on a model. Here's my very basic controller action for "providers/add":
public function addAction()
{
if ($this->request->isPost()) {
$provider = new Providers();
if ($provider->save($this->request->getPost())) {
return $this->response->redirect('');
} else {
$this->flashSession->error(implode(', ', $provider->getMessages()));
return $this->response->redirect('providers/add');
}
}
}
And here is my model's validation function:
public function validation()
{
$this->validate(new PresenceOf(['field' => 'last_name']));
$this->validate(new Email(['field' => 'email', 'allowEmpty' => true]));
return $this->validationHasFailed() != true;
}
The validation function seems to be totally ignored, because I never get an error message even when last_name is an empty string. I have even tried echoing some info in the validation function followed by "exit" but nothing happens, so it seems the validation function is never even run. Any ideas?