cakephp Archives

How to upload a file on AWS S3 from Cakephp 3.9

Author - Webner
|
0 Comments
|

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 Read more…

How to validate records before inserting in CakePHP 2.X

Author - Webner
|
0 Comments
|

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 do exactly that for us.

Read more…

Reformat associative array in CakePHP 2.*

Author - Webner
|
0 Comments
|

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 and sometimes use one of the column Read more…

Validation vs. Application Rules In CakePHP

Author - Pawandeep Kaur
|
0 Comments
|

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 an email address Read more…

Insert and update bulk data in CakePHP 3.7

Author - Kailash Kumar
|
0 Comments
|

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 function is used to update Read more…

How to run CakePHP 3.7 Shell Commands in Heroku console

Author - Kailash Kumar
|
0 Comments
|

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 Read more…

How to Install nginx and configure it for CakePHP

Author - Manoj Thakur
|
0 Comments
|

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 CakePHP version.

What Read more…

How to Detect Mobile devices in php

Author - Gopi Garg

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 we use the media queries and Read more…

Class ‘App\Controller\Aws\S3\S3Client’ not found error in CakePHP 3.*

Author - Kailash Kumar

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 Read more…

Sort query result according to search conditions in CakePHP 2.

Author - Kailash Kumar
|
0 Comments
|

How to sort query result according to various search conditions in fetch query of CakePHP 2.

Problem: Priority based sorting of records

Example: Search a string (“Proposalways StudySection”) and display records in following order:

Contain all words (“Proposalways StudySection”) in Read more…

What is the purpose of multiple .htaccess files in CakePHP?

Author - Varun Chopra

Purpose of multiple .htaccess files in CakePHP

In Cakephp, contained .htaccess files are as follows:

newcakeproject/.htaccess
/app/.htaccess
/app/webroot/.htaccess

1. newcakeproject/.htaccess

CakePHP root directory .htaccess redirects everything to your CakePHP app (means to webroot). We can also redirect the url to some Read more…

Using Google Search Operators

Author - Mayank Srivastava

Using Google Search Operators for Better Results

Google defines Search Operators as the “words or symbols in one’s search phrase that make the search results more precise”. These operators have their basis in coding as they are nothing but shortcuts in procuring the best results Read more…

How to use CakePHP Validation class

Author - Kailash Kumar
|
0 Comments
|

How to use CakePHP Validation class

We can use CakePHP validation functions and speed up development. These functions already follow the correct rules so we don’t need to write custom code.

Example:
In Controller:

$validate = new Validation();
$string = ‘Name123’;
$result = $validate->alphaNumeric ( $string );
if ($result Read more…

Sending Emails in CakePHP with Example

Author - Sahil Bhalla
|
0 Comments
|

What support/library is there in CakePHP for sending emails and how to use it?

In CakePHP3, there are Transport and Email classes available under Cake/Network/Email namespace that are used for sending emails. After an update in the version 3.1 email functionality has Read more…

Convert HTML to pdf using mpdf plugin in cakePHP

Author - Sahil Bhalla
|
0 Comments
|

How to use mpdf plugin in cakePHP to convert HTML documents to pdf?

mPDF is a PHP library which is used to generate PDF files from HTML Documents. It converts utf-8 encoded documents and also supports almost all languages including Arabic and Hebrew. It includes Read more…