Since the latest version of Phalcon was released, the examples provided in the documentation do not seem to work correctly.
Firstly, I create a new model with DevTools at the command line using phalcon model User
.
Then, I amend the validation()
function. My models\User.php
file:
use Phalcon\Mvc\Model\Validator\Email as Email;
use Phalcon\Mvc\Model\Validator\Uniqueness as Uniqueness;
use Phalcon\Mvc\Model\Validator\StringLength as StringLength;
class User extends \Phalcon\Mvc\Model
{
public function validation()
{
$this->validate(
new Email(
array(
'field' => 'email',
'message' => 'Please enter a valid email'
)
)
);
$this->validate(
new Uniqueness(
array(
'field' => 'email',
'message' => 'Your email is already in use'
)
)
);
$this->validate(
new StringLength(
array(
'field' => 'password',
'min' => 4,
'max' => 30,
'minMessage' => 'Your password must be at least 4 characters',
'maxMessage' => 'Your password must be less than 30 characters'
)
)
);
if ($this->validationHasFailed() == true) {
return false;
}
return true;
}
}
However, this throws the following error:
Catchable fatal error: Argument 1 passed to Phalcon\Mvc\Model::validate() must implement interface Phalcon\ValidationInterface, instance of Phalcon\Mvc\Model\Validator\Email given in C:\xampp\htdocs\app\models\User.php on line 27
What does this mean? I believed that Phalcon\Validation
and Phalcon\Mvc\Model\Validator
were completely different beasties (the latter providing more functionality)?