Tag: cakephp
How to upload a file on AWS S3 from Cakephp 3.9
First, we need to install aws-sdk for PHP in the CakePHP project. To install it we can run the below command: composer require aws/aws-sdk-php Code to upload a file: Template Code: <?= $this->Form->create($product, [‘enctype’ => ‘multipart/form-data’]) ?> <fieldset> <legend></legend> <?php
How to validate records before inserting in CakePHP 2.X
Problem: Sometimes we only need to validate records before inserting operations in CakePHP. In the case of bulk insertion and CSV records validation, it’s very difficult to validate individual fields of bulk records. Solution: array (‘validate’ => ‘only’) parameter will
Reformat associative array in CakePHP 2.*
How to use CakePHP 2.* Hash::combine method to reformat associative and find results array? Sometimes we do a lot in the code to reformat find query results, to remove the table name (for example, User, Article, etc) from the array
Validation vs. Application Rules In CakePHP
CakePHP uses a two-layered approach to validation: 1. Validation It determines basic validity. It ensures that the data types, size, and format of data are correct. When we call newEntity() or patchEntity() methods, validations are triggered. For example, checking if
Insert and update bulk data in CakePHP 3.7
How to Insert and update bulk data in CakePHP 3.7? We can insert and update multiple records using “saveMany($entities)” function. We can create entities array from “newEntities() / patchEntities()” functions. newEntities function is used to insert new data and patchEntities
How to run CakePHP 3.7 Shell Commands in Heroku console
Learn how to run CakePHP 3.7 Shell Commands in Heroku console 1. Create myCommandShell.php file in src/Shell folder with below content <?php namespace App\Shell; use Cake\Console\Shell; use App\Controller\PagesController; class myCommandShell extends Shell { public function main() { // do your
How to Install nginx and configure it for CakePHP
How to Install nginx and configure it for CakePHP Quick Summary: 1. What is Web Server? 2. What is Nginx? 3. Nginx Installation. 4. Create server block (VirtualHost). 5. Install CakePHP and configure it for Nginx. 6. How to check
How to Detect Mobile devices in php
Detect mobile device php code We often need to detect if site visitor is using an iPad, a smartphone or any other mobile device in order to change website appearance and even make it faster by reducing data load. Normally
Class ‘App\Controller\Aws\S3\S3Client’ not found error in CakePHP 3.*
How to resolve “Class ‘App\Controller\Aws\S3\S3Client’ not found” error in CakePHP 3.* Problem: Class ‘App\Controller\Aws\S3\S3Client’ not found error occurs when we are trying to create S3Client class object with given code (code copied from github): $s3 = new Aws\S3\S3Client ( [