Files
money/vendor/j4mie/paris/docs/validation.rst
2023-06-16 02:08:47 +00:00

27 lines
1.5 KiB
ReStructuredText
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

A word on validation
====================
Its generally considered a good idea to centralise your data validation
in a single place, and a good place to do this is inside your model
classes. This is preferable to handling validation alongside form
handling code, for example. Placing validation code inside models means
that if you extend your application in the future to update your model
via an alternative route (say a REST API rather than a form) you can
re-use the same validation code.
Despite this, Paris doesnt provide any built-in support for validation.
This is because validation is potentially quite complex, and often very
application-specific. Paris is deliberately quite ignorant about your
actual data - it simply executes queries, and gives you the
responsibility of making sure the data inside your models is valid and
correct. Adding a full validation framework to Paris would probably
require more code than Paris itself!
However, there are several simple ways that you could add validation to
your models without any help from Paris. You could override the
``save()`` method, check the data is valid, and return ``false`` on
failure, or call ``parent::save()`` on success. You could create your
own subclass of the ``Model`` base class and add your own generic
validation methods. Or you could write your own external validation
framework which you pass model instances to for checking. Choose
whichever approach is most suitable for your own requirements.