You can implement the validations just in the model, in both cases they will be executed binding the data got from the request or directly binding the data to the model.
<?php
use Phalcon\Mvc\Model\Validator\InclusionIn,
Phalcon\Mvc\Model\Validator\Uniqueness;
class Robots extends \Phalcon\Mvc\Model
{
public $id;
public $name;
public $type;
public function validation()
{
$this->validate(new InclusionIn(
array(
"field" => "type",
"domain" => array("Mechanical", "Virtual")
)
));
$this->validate(new Uniqueness(
array(
"field" => "name",
"message" => "The robot name must be unique"
)
));
return $this->validationHasFailed() != true;
}
}
Directly assign values to model:
$robot = new Robots();
$robot->name = 'Voltron';
$robot->type = 'Mechanical';
$robot->save(); // validation is performed here
var_dump($robot->getMessages()); // get messages
Binding data from the form:
$robot = new Robots();
$form->bind($this->request->getPost(), $robot);
$robot->save(); // validation is performed here
var_dump($robot->getMessages()); // get messages