Category : cakephp-4.x

I’m creating a plugin FileManager in cakephp4. (This plugin is in app/plugins/FileManager) This plugin has an UploaderHelper that contains a method to generate an input file + the files that are associated to the field. In this method I’m using the plugin CakephpGlide (https://github.com/ADmad/cakephp-glide) to display thumbnails of the images that are associated to the ..

Read more

What I have done: fresh composer install of CakePHP 4.3.1 bin/cake bake plugin Admin config the db connection successfully bin/cake bake all Articles –plugin Admin put this route $routes->connect(‘/admin/articles’, [‘plugin’ => ‘Admin’, ‘controller’ => ‘Articles’]); in the config/routes.php opened the plugins/Admin/src/Controller/ArticlesController.php and change the line use AppControllerAppController; to the use AdminControllerAppController; However, after trying to ..

Read more

I’m creating a plugin FileManager where all uploads are stored in a single table. This plugin has an AttachmentBehavior that attaches a hasMany association. I use multi-files input in templates Articles/add.php and Articles/edit.php to upload files that will be linked to an article : // Example in Articles/edit.php echo $this->Form->create($article, [‘type’ => ‘file’]); echo $this->Form->control(‘title’, ..

Read more

I’m creating a plugin FileManager and I’m trying to create a validation provider FileValidation in this plugin to provide some pre-build rules. I’ve put FileValidation class in plugins/FileManager/src/Validation/FileValidation.php : <?php declare(strict_types=1); namespace FileManagerValidation; use CakeValidationValidation; class FileValidation { /** * Check mime type */ public static function mimeImage($file): bool { return Validation::mimeType($file, [ ‘image/png’, ‘image/gif’, ..

Read more

Here is the validation for my input file "image" : public function validationDefault(Validator $validator): Validator { $validator = parent::validationDefault($validator); $validator ->allowEmptyFile(‘image’) ->add(‘image’, ‘uploadError’, [ ‘rule’ => function ($value, $context) { foreach ($value as $v) { return Validation::uploadError($v, true); } }, ‘last’ => true, ‘message’ => ‘Upload error’ ]) ->add(‘image’, ‘mimeType’, [ ‘rule’ => function ($value, ..

Read more