Since I learned about MVC, I always checked my form data in my controllers, which I used to when I looked at CodeIgniters code, but I found out that its way of doing certain operations is not the best, it just does its job.
Should all data be validated by domain objects? And if so it should be done in setters like this:
public function setFirstName($firstName) {
Also, for example, if I handle basic user registration, my User class does not have the $confirmPassword , so I won’t do
$user->setConfirmPassword($confirmPassword); .
One way to check if the two entered passwords match is to set $password and do something like
$user->setPassword($password); if(!$user->matchPassword($confirmPassword)) { throw new PasswordsNotEqualException('Some message'); }
and it will be done at the service level, which I would have thought?
Any advice that would help me in the right direction would be great. Thanks.
source share