In the CakePHP 3 docs there's a section on Reusable Validators: https://book.cakephp.org/3.0/en/core-libraries/validation.html#creating-reusable-validators
It doesn't say how you use them, in a Controller though. Can anyone give an example?
I have a particular application which allows .csv files to be uploaded. The validation for a .csv file in the application is always the same: check it's MIME type, check the size, check the extension, etc.
So my plan was to implement this as a reusable validator - is that correct?
I have an UploadsController.php
with an upload()
function, which is where I want to use this to validate data coming from a form. I'm confused because I'm not creating an Entity at this point - but rather just trying to validate my file - so all this patchEntity()
stuff in the docs makes no sense here.
I find the documentation on validation for Cake 3 very confusing, because there's a section under the ORM (https://book.cakephp.org/3.0/en/orm/validation.html) where it says
Validation rules are defined in the Table classes
But later on, it has a completely different section on validating Entities (https://book.cakephp.org/3.0/en/core-libraries/validation.html#validating-entities).
Then we have Reusable Validators..... and various other things.
Since Table and Entity model classes in Cake 3 differ, can someone explain how you would go about validating something like a file upload, particularly given that there may even be no table at all involved?
And what if you have a combination on a form where you need to use both a Reusable Validator (for a common task like validating a .csv), and also a separate set of rules for a specific table that might be in a Table model class?
UploadsController:upload()
. If I were to createsrc/Model/Validation/CsvValidator.php
how so I then pass the form data to that, viaUploadsController:upload()
and get back the validation messages? – Andy