From dda2834d3792cd4aaff6d005159f2fc0c27c2256 Mon Sep 17 00:00:00 2001 From: Mariano Conti Date: Tue, 1 Mar 2016 13:31:19 -0300 Subject: [PATCH 1/2] Add :model identifier --- src/Model/Behavior/UploadBehavior.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Model/Behavior/UploadBehavior.php b/src/Model/Behavior/UploadBehavior.php index c1d8a5e..5e5c3ec 100644 --- a/src/Model/Behavior/UploadBehavior.php +++ b/src/Model/Behavior/UploadBehavior.php @@ -261,6 +261,7 @@ protected function _getUploadPath(Entity $entity, $path = false, $extension = fa $identifiers = [ ':id' => $entity->id, + ':model' => strtolower($entity->source()), ':md5' => md5(rand() . uniqid() . time()), ':y' => date('Y'), ':m' => date('m') From 85b1e87c3dae359b86a472a5927f9dde1f20d9da Mon Sep 17 00:00:00 2001 From: Mariano Conti Date: Tue, 1 Mar 2016 13:34:35 -0300 Subject: [PATCH 2/2] Update README.md --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7d5bd5c..d893d33 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ In your model `initialize()`: $this->addBehavior('Xety/Cake3Upload.Upload', [ 'fields' => [ 'avatar' => [ - 'path' => 'upload/avatar/:id/:md5' + 'path' => 'upload/avatar/:model/:id/:md5' ] ] ] @@ -57,6 +57,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the ### Identifiers * **:id** Id of the Entity (It can be the user Id if you are using this for the users table for example) +* **:model** Table name of the Entity * **:md5** A random and unique identifier with 32 characters. i.e : *bbebb3c3c5e76a46c3dca92c9395ee65* * **:y** Based on the current year. i.e : *2014* * **:m** Based on the current month. i.e : *09* @@ -70,7 +71,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the $this->addBehavior('Upload', [ 'fields' => [ 'avatar' => [ - 'path' => 'upload/avatar/:id/:md5' + 'path' => 'upload/avatar/:model/:id/:md5' ] ], 'suffix' => '_anotherName' @@ -88,7 +89,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the $this->addBehavior('Upload', [ 'fields' => [ 'avatar' => [ - 'path' => 'upload/avatar/:id/:md5', + 'path' => 'upload/avatar/:model/:id/:md5', 'overwrite' => false ] ] @@ -104,7 +105,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the $this->addBehavior('Upload', [ 'fields' => [ 'avatar' => [ - 'path' => 'upload/avatar/:id/:md5', + 'path' => 'upload/avatar/:model/:id/:md5', 'overwrite' => true, 'defaultFile' => 'default_avatar.png' ] @@ -121,7 +122,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the $this->addBehavior('Upload', [ 'fields' => [ 'avatar' => [ - 'path' => 'upload/avatar/:id/:md5', + 'path' => 'upload/avatar/:model/:id/:md5', 'prefix' => '../' ] ] @@ -142,7 +143,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the $this->addBehavior('Upload', [ 'fields' => [ 'avatar' => [ - 'path' => 'upload/avatar/:id/:md5', + 'path' => 'upload/avatar/:model/:id/:md5', 'prefix' => '../' ] ] @@ -151,7 +152,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the // In a view, with the Html Helper: Html->image($User->avatar) ?> - // Output : + // Output : ``` ## Contribute