Personally I would use a Form
https://docs.phalcon.io/4.0/en/forms
Create the form and add the elements you need there. Also add the necessary validators in the form itself. When you receive the input you can validate your form and that will return true
or you will have messages for validators that failed.
You can then use something like this:
$customer = Customers::findFirst($customerId);
$form = new CustomerForm($customer);
$form->bind($_POST, $customer);
if (false !== $form->isValid()) {
$customer->save();
}
If that does not validate you have errors. If it does validate you will save the model directly. Note that the form elements need to have the same names as the elements in your model. If you want to obscure this, then ou will need to pass the $_POST
in your isValid
and if everything is OK you will be able to get the data from the request, sanitize it and save it to your model.
Using the form and bind
allows you to have validators on the form itself and also attach filters which will allow you to ensure your data has the correct case and sanitizations.