From a22d76018b3c7e8520be81e4ee4e4a8202263368 Mon Sep 17 00:00:00 2001 From: Dave Baker Date: Thu, 15 Oct 2015 10:18:36 +0100 Subject: [PATCH 1/3] Remove section about editing composer.json Best practice is to add composer dependencies through the `composer require` terminal command and not through editing the composer.json file --- docs/installation.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index cbf170f..a96d115 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -11,8 +11,6 @@ In your terminal you can use $ composer require 'davidyell/proffer:~0.4' ``` -If you would rather edit your `composer.json` you can add it to your `composer.json` in your require section `"davidyell/proffer": "dev-master"` and then run `composer update`. - It's always advised to lock your dependencies to a specific version number. You can [check the releases](https://github.com/davidyell/CakePHP3-Proffer/releases), or [read more about versions on Composer.org](https://getcomposer.org/doc/01-basic-usage.md#package-versions). For more information about [installing plugins with CakePHP](http://book.cakephp.org/3.0/en/plugins.html#installing-a-plugin-with-composer), check the book. From 95012ddb76c6bd9bf13d7709a6141d5a95fb81bc Mon Sep 17 00:00:00 2001 From: Hiroki Shimizu Date: Tue, 20 Oct 2015 19:10:08 +0900 Subject: [PATCH 2/3] Correct typo on shell parameter "image-class" --- src/Shell/ProfferShell.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shell/ProfferShell.php b/src/Shell/ProfferShell.php index 6a58831..3f0b6da 100644 --- a/src/Shell/ProfferShell.php +++ b/src/Shell/ProfferShell.php @@ -114,7 +114,7 @@ public function generate($table) } if (!empty($this->param('image-class'))) { - $class = (string)$this->param('image_class'); + $class = (string)$this->param('image-class'); $transform = new $class($this->Table, $path); } else { $transform = new ImageTransform($this->Table, $path); From ed10a6983d5e968b33c0249915ca7bfc44b51796 Mon Sep 17 00:00:00 2001 From: David Yell Date: Thu, 22 Oct 2015 15:13:08 +0100 Subject: [PATCH 3/3] Validation docs update Removed the usage for the old rules which have been removed from the validation class. Also added a note about making the field required for create, but not on update. --- docs/validation.md | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/docs/validation.md b/docs/validation.md index cc9061c..7080f10 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -3,8 +3,7 @@ This manual page deals with how to use the included ProfferRules validation prov your application. ##Built-in validation provider -Proffer comes with some basic validation rules which you can use to validate your uploads. In order to use these you -will need to load the validation rules and apply them to your field. +Proffer comes an extra validation rule to check the dimensions of an uploaded image. Other rules are provided by the core and are listed below. In your validation function in your table class you'll need to add the validator as a provider and then apply the rules. @@ -12,26 +11,6 @@ In your validation function in your table class you'll need to add the validator provider('proffer', 'Proffer\Model\Validation\ProfferRules'); -// Check the filesize in bytes -$validator->add('photo', 'proffer', [ - 'rule' => ['filesize', 2000000], - 'provider' => 'proffer' -]) - -// Make sure the extension matches -->add('photo', 'proffer', [ - 'rule' => ['extension', ['jpg', 'jpeg', 'png']], - 'message' => 'Invalid extension', - 'provider' => 'proffer' -]) - -// Ensure that the upload is the correct mime type -->add('photo', 'proffer', [ - 'rule' => ['mimetype', ['image/jpeg', 'image/png']], - 'message' => 'Not the correct mime type', - 'provider' => 'proffer' -]) - // Set the thumbnail resize dimensions ->add('photo', 'proffer', [ 'rule' => ['dimensions', [ @@ -45,5 +24,20 @@ $validator->add('photo', 'proffer', [ You can [read more about custom validation providers in the book](http://book.cakephp.org/3.0/en/core-libraries/validation.html#adding-validation-providers). +If you need to validate other aspects of the uploaded file, there are a number of core validation methods you might find helpful. +* [Extension](http://api.cakephp.org/3.0/class-Cake.Validation.Validation.html#_extension) +* [File size](http://api.cakephp.org/3.0/class-Cake.Validation.Validation.html#_fileSize) +* [Mime type](http://api.cakephp.org/3.0/class-Cake.Validation.Validation.html#_mimeType) + +## Basic validation rules +If you want your users to submit a file when creating a record, but not when updating it, you can configure this using the basic Cake rules. + +```php +$validator + ->requirePresence('image', 'create') + ->allowEmpty('image', 'update'); +``` + +So now your users do not need to upload a file every time they update a record. [< Configuration](configuration.md) | [Customisation >](customisation.md)