I think that should be done in the controller... which you did, sort of. The knowledge that a password needs to be validated before updating is still held by the controller and not the model, but for reusability I think I'd prefer this:pytrin wrote:Ok, good spot![]()
What you are referring to is indeed outside the scope of the model. I was thinking you were talking about the actual data set validation rules, but for the use-case you described you need form validation rules which are context specific.
The model handles all the rules that pertain to the data it is manipulating - but nothing other than that. If you want to make sure the entered password a user submits is valid before updating his email then you should run that check before invoking the model validation routines. You could do that either in the controller, or add specific validation methods to the model (I like that option better if it has to retrieve data, like the password case you described).
Code: Select all
if ($userMapper->validPassword ($password)):
$userMapper->updateUser ($user);
else:
$view->setError ('invalid password');
endif;