Hi,
after lot's of code not working at the new version I decided to validate my data inside my model instead of my form. I hope this will fix some problems I have.
The problem is that the validation function inside my model isn't executed.
Controller
public function createAction() {
$user_run = new UsersRuns();
$success = $user_run->save($this->request->getPost());
if ($success) {
echo "Thanks for registering!";
} else {
echo "Sorry, the following problems were generated: ";
foreach ($user_run->getMessages() as $message) {
echo $message->getMessage(), "<br/>";
}
}
$this->view->disable();
}
Model
namespace Run\Backend\Models;
use Phalcon\Validation;
use Phalcon\Mvc\Model;
use Phalcon\Validation\Validator\PresenceOf;
class UsersRuns extends Model {
public function initialize() {
$this->hasOne('users_id', 'Users', 'id');
}
public function validation() {
$validator = new Validation();
$validator->add(
'date', new PresenceOf([
'message' => 'Please enter a date'
])
);
if ($this->validationHasFailed() == true) {
return false;
}
}
I always get the default messages from $message->getMessage(). What I am doing wrong?