SlideShare a Scribd company logo
Cake PHP
Version : 3.4 (X)
By : Jyotisankar Pradhan
Requirements
1. PHP 5.6.0 or Greater
2. Webserver (Apache, Nginx) preferably or Microsoft IIS
3. MySQL (5.1.10 or greater), PgSQL, Microsoft SQL Server, SQLite 3
4. PDO is default required.
Installation
1. Install composer
2. Once the installation is done you need to move your composer.phar file to
/usr/local/bin/composer
3. You can also install cakePHP using Oven
4. Oven is a simple PHP script which checks necessary system requirements
and will help install CakePHP with click.. Click.. Click… Please refer
https://github.com/CakeDC/oven to install it.
Create a CakePHP Project
=> If your composer has been installed globally on your server or local machine
please use “composer self-update && composer create-project --prefer-dist
cakephp/app my_app_name” else use “php composer.phar create-project --
prefer-dist cakephp/app my_app_name”
=> my_app_name is the name of the directory/project.
=> Now if you will run localhsot/my_app_name you can see the default
application running on your local machine/server.
Few other things to note
1. Make sure mode_rewrite is enabled
2. If you wish to keep your codebase up to date with latest CakePHP changes,
you need to change the CakePHP version in composer.json. Like wise
“"cakephp/cakephp": "3.4.*" to “"cakephp/cakephp": "3.x.*", so that when
you update your composer by composer update you will get the latest fixes
on your local machine/server.
3. You need to have/install correct PDO extension for database that you are
using.
Database Configuration
=> Go to config/app.php, You can set the host, database, username and
password. The actual connection information is fed in
“CakeDatasourceConnectionManager ”.
=> You can also define as many connection as you want using
“CakeDatasourceConnectionManager”.
=> In this connection manager you can also set timezone, connection type
wheather to keep it persistent or not.
Example
'Datasources' => [
'default' => [
'className' => 'CakeDatabaseConnection',
'driver' => 'CakeDatabaseDriverMysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'my_app',
'password' => 'sekret',
'database' => 'my_app',
Manage Connections
1. Using CakeDatasourceConnectionManager, you can access the
connection available in your application
2. You can get the connection using
“CakeDatasourceConnectionManager::get($name)”. $name can be
default or any other cases that you have declared.
3. You can also create new connection at run time using config() and get()
methods.
4. “ConnectionManager::config('my_connection', $config);
Simple CRUD with and without Bootstrap
1. Create Controller with proper naming convention.(XxxsController.php)
2. Create a Model File (XxxTable.php)
3. Create template file (CTP) inside Template (Xxxs/index.ctp)
4. Change default page in routes.php
5. Using Bootstrap, for sample lets see (http://bootswatch.com)
6. Lets check……..
Middleware
CakePHP provides several middleware few of them are :
1. CakeErrorMiddlewareErrorHandlerMiddleware (
=> It traps exceptions from the wrapped middleware and renders an error
page using the Error & Exception Handling Exception handler.
1. CakeRoutingAssetMiddleware
=> It checks the request are are for cake theme or from plugin assets,
wheateher its on themes webroot or in plugins webroot
Middleware
3. CakeI18nMiddlewareLocaleSelectorMiddleware
=> It automatically switch language from the Accept-Language header sent by
the browsers
Deployment
1. To implement the project in 2 or 3 different server, you have to send the
codebase through git and rest thing can be done by composer (Composer
install or Composer Update). It automatically check the dependencies and
folder permission etc.
2. If anyone working on FTP, he has to upload the library manually and have
to give the folder permission as expected.
3. You can set the debug mode True/False based on server to server by
environment variable in your apache settings.
Deployment
SetEnv CAKEPHP_DEBUG 1 (In your apache configuration)
And then you can set the debug level dynamically in app.php:
$debug = (bool)getenv('CAKEPHP_DEBUG');
return [
'debug' => $debug,
];
Deployment
4. To increase your application performance in production once deployment is
done through
php composer.phar dumpautoload -o
After doing this you need set your js/css/images etc path (webroot) through
symlink
bin/cake plugin assets symlink (This command will symlink your webroot
directory)
Cache
1. Default CakePHP cache flused once in a year, but you can manage it
through config/app.php
2. We can also set the cache for schema description and table listings.
3. We can also flush individual cache if we know the key
Cache::delete() will allow you to completely remove a cached object
Cache::delete('my_key');
Cache
4. If you wish to clear all cache data that may be configured in APC, Memcache
etc
Cache::clear(true); (Will only clear expired keys.)
Cache::clear(false); (Will clear all keys.)
5. We can also use Cache to store/remove common find data. Example :
Cache
public function postSave($event, $entity, $options = [])
{
if ($entity->isNew()) {
Cache::clearGroup(post, 'home');
}
}
Cache
6. Enable or Disable Cache globally
Cache::disable(); (Disable all cache reads, and cache writes.)
Cache::enable(); (Re-enable all cache reads, and cache writes.)
Other Important thing
1. You can create your own data type in CakePHP using toPHP, toDatabase,
toStatement and marshal, once you are done you can map your Custom
data type to SQL expression
(https://book.cakephp.org/3.0/en/orm/database-
basics.html#CakeDatasourceConnectionManager)
2. In CakePHP DRY(Don’t repeat yourself) is used to allow you to code things
once and re-use them across your application.
3. CDN is default configured you can define the path of cdn in configuration
Other Important thing
4. How to write custom sql query
use CakeDatasourceConnectionManager;
$connection = ConnectionManager::get('default');
$results = $connection
->execute('SELECT * FROM articles WHERE id = :id', ['id' => 1])
->fetchAll('assoc');
Other Important thing
$connection->insert('articles', [
'title' => 'A New Article',
'created' => new DateTime('now')
], ['created' => 'datetime']);
5. Create Relationship between Tables
Relationship Association Type Example
one to one hasOne A user has one profile.
one to many hasMany A user can have multiple recipes.
many to one belongsTo Many recipes belong to a user.
many to many hasAndBelongsToMany Recipes have, and belong to, many
ingredients.
Example :
class IngredientsTable extends Table
{
public function initialize(array $config)
{
// have additional data on your IngredientsProducts table
$this->belongsToMany('Products', [
class ProductsTable extends Table
{
public function initialize(array $config)
{
$this->belongsToMany('Ingredients', [
'through' => 'IngredientsProducts',
]);
}
class IngredientsProductsTable extends Table
{
public function initialize(array $config)
{
$this->belongsTo('Ingredients');
$this->belongsTo('Products');
}
}
Migration
Laravel VS Cakephp
Migration needs to be enabled through composer, by default its enabled
through the setup
Else
Plugin::load('Migrations'); in your bootsrap.php file
Once you have created in the config/Migrations folder, you will be able to
execute the following migrations command to create the table in your database:
bin/cake migrations migrate

More Related Content

What's hot

Mule caching strategy with redis cache
Mule caching strategy with redis cacheMule caching strategy with redis cache
Mule caching strategy with redis cache
Priyobroto Ghosh (Mule ESB Certified)
 
Apache Web server Complete Guide
Apache Web server Complete GuideApache Web server Complete Guide
Apache Web server Complete Guidewebhostingguy
 
Build Automation 101
Build Automation 101Build Automation 101
Build Automation 101
Martin Jackson
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloud
Tahsin Hasan
 
MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher
akashdprajapati
 
Fixing Growing Pains With Puppet Data Patterns
Fixing Growing Pains With Puppet Data PatternsFixing Growing Pains With Puppet Data Patterns
Fixing Growing Pains With Puppet Data Patterns
Martin Jackson
 
Drupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case StudyDrupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case Study
hernanibf
 
Using RequireJS with CakePHP
Using RequireJS with CakePHPUsing RequireJS with CakePHP
Using RequireJS with CakePHP
Stephen Young
 
How to migrate Cakephp 1.x to 2.x
How to migrate Cakephp 1.x to 2.xHow to migrate Cakephp 1.x to 2.x
How to migrate Cakephp 1.x to 2.x
Andolasoft Inc
 
Box connector Mule ESB Integration
Box connector Mule ESB IntegrationBox connector Mule ESB Integration
Box connector Mule ESB Integration
AnilKumar Etagowni
 
Apache Web Services
Apache Web ServicesApache Web Services
Apache Web Serviceslkurriger
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Apache hadoop 2_installation
Apache hadoop 2_installationApache hadoop 2_installation
Apache hadoop 2_installationsushantbit04
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With Rpm
Martin Jackson
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet backdoor
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
glslarmenta
 
Heavy Web Optimization: Backend
Heavy Web Optimization: BackendHeavy Web Optimization: Backend
Heavy Web Optimization: Backend
Võ Duy Tuấn
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REX
Saewoong Lee
 
Integrate with database by groovy
Integrate with database by groovyIntegrate with database by groovy
Integrate with database by groovy
Son Nguyen
 

What's hot (20)

Mule caching strategy with redis cache
Mule caching strategy with redis cacheMule caching strategy with redis cache
Mule caching strategy with redis cache
 
Apache Web server Complete Guide
Apache Web server Complete GuideApache Web server Complete Guide
Apache Web server Complete Guide
 
Build Automation 101
Build Automation 101Build Automation 101
Build Automation 101
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloud
 
MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher
 
Fixing Growing Pains With Puppet Data Patterns
Fixing Growing Pains With Puppet Data PatternsFixing Growing Pains With Puppet Data Patterns
Fixing Growing Pains With Puppet Data Patterns
 
Drupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case StudyDrupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case Study
 
Using RequireJS with CakePHP
Using RequireJS with CakePHPUsing RequireJS with CakePHP
Using RequireJS with CakePHP
 
How to migrate Cakephp 1.x to 2.x
How to migrate Cakephp 1.x to 2.xHow to migrate Cakephp 1.x to 2.x
How to migrate Cakephp 1.x to 2.x
 
Box connector Mule ESB Integration
Box connector Mule ESB IntegrationBox connector Mule ESB Integration
Box connector Mule ESB Integration
 
Apache Web Services
Apache Web ServicesApache Web Services
Apache Web Services
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
BPMS1
BPMS1BPMS1
BPMS1
 
Apache hadoop 2_installation
Apache hadoop 2_installationApache hadoop 2_installation
Apache hadoop 2_installation
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With Rpm
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
 
Heavy Web Optimization: Backend
Heavy Web Optimization: BackendHeavy Web Optimization: Backend
Heavy Web Optimization: Backend
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REX
 
Integrate with database by groovy
Integrate with database by groovyIntegrate with database by groovy
Integrate with database by groovy
 

Similar to Cake php

Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2
markstory
 
Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3
kidtangerine
 
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptLecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
SreejithVP7
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi Mensah
PHP Barcelona Conference
 
Cakephp's Cache
Cakephp's CacheCakephp's Cache
Cakephp's Cache
vl
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
Elizabeth Smith
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
Toufiq Mahmud
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
Bo-Yi Wu
 
Building drupal web farms with IIS - part 1
Building drupal web farms with IIS - part 1Building drupal web farms with IIS - part 1
Building drupal web farms with IIS - part 1
Alessandro Pilotti
 
DevOps Hackathon: Session 3 - Test Driven Infrastructure
DevOps Hackathon: Session 3 - Test Driven InfrastructureDevOps Hackathon: Session 3 - Test Driven Infrastructure
DevOps Hackathon: Session 3 - Test Driven Infrastructure
Antons Kranga
 
Symfony internals [english]
Symfony internals [english]Symfony internals [english]
Symfony internals [english]
Raul Fraile
 
DevOps hackathon Session 2: Basics of Chef
DevOps hackathon Session 2: Basics of ChefDevOps hackathon Session 2: Basics of Chef
DevOps hackathon Session 2: Basics of Chef
Antons Kranga
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdf
HumphreyOwuor1
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Box
guest34a3a419
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Box
Jayanta Dash
 

Similar to Cake php (20)

Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2
 
instaling
instalinginstaling
instaling
 
instaling
instalinginstaling
instaling
 
instaling
instalinginstaling
instaling
 
instaling
instalinginstaling
instaling
 
Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3
 
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptLecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi Mensah
 
Cakephp's Cache
Cakephp's CacheCakephp's Cache
Cakephp's Cache
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
 
Php
PhpPhp
Php
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Building drupal web farms with IIS - part 1
Building drupal web farms with IIS - part 1Building drupal web farms with IIS - part 1
Building drupal web farms with IIS - part 1
 
DevOps Hackathon: Session 3 - Test Driven Infrastructure
DevOps Hackathon: Session 3 - Test Driven InfrastructureDevOps Hackathon: Session 3 - Test Driven Infrastructure
DevOps Hackathon: Session 3 - Test Driven Infrastructure
 
Symfony internals [english]
Symfony internals [english]Symfony internals [english]
Symfony internals [english]
 
DevOps hackathon Session 2: Basics of Chef
DevOps hackathon Session 2: Basics of ChefDevOps hackathon Session 2: Basics of Chef
DevOps hackathon Session 2: Basics of Chef
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdf
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Box
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Box
 

Recently uploaded

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 

Recently uploaded (20)

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 

Cake php

  • 1. Cake PHP Version : 3.4 (X) By : Jyotisankar Pradhan
  • 2. Requirements 1. PHP 5.6.0 or Greater 2. Webserver (Apache, Nginx) preferably or Microsoft IIS 3. MySQL (5.1.10 or greater), PgSQL, Microsoft SQL Server, SQLite 3 4. PDO is default required.
  • 3. Installation 1. Install composer 2. Once the installation is done you need to move your composer.phar file to /usr/local/bin/composer 3. You can also install cakePHP using Oven 4. Oven is a simple PHP script which checks necessary system requirements and will help install CakePHP with click.. Click.. Click… Please refer https://github.com/CakeDC/oven to install it.
  • 4. Create a CakePHP Project => If your composer has been installed globally on your server or local machine please use “composer self-update && composer create-project --prefer-dist cakephp/app my_app_name” else use “php composer.phar create-project -- prefer-dist cakephp/app my_app_name” => my_app_name is the name of the directory/project. => Now if you will run localhsot/my_app_name you can see the default application running on your local machine/server.
  • 5. Few other things to note 1. Make sure mode_rewrite is enabled 2. If you wish to keep your codebase up to date with latest CakePHP changes, you need to change the CakePHP version in composer.json. Like wise “"cakephp/cakephp": "3.4.*" to “"cakephp/cakephp": "3.x.*", so that when you update your composer by composer update you will get the latest fixes on your local machine/server. 3. You need to have/install correct PDO extension for database that you are using.
  • 6. Database Configuration => Go to config/app.php, You can set the host, database, username and password. The actual connection information is fed in “CakeDatasourceConnectionManager ”. => You can also define as many connection as you want using “CakeDatasourceConnectionManager”. => In this connection manager you can also set timezone, connection type wheather to keep it persistent or not.
  • 7. Example 'Datasources' => [ 'default' => [ 'className' => 'CakeDatabaseConnection', 'driver' => 'CakeDatabaseDriverMysql', 'persistent' => false, 'host' => 'localhost', 'username' => 'my_app', 'password' => 'sekret', 'database' => 'my_app',
  • 8. Manage Connections 1. Using CakeDatasourceConnectionManager, you can access the connection available in your application 2. You can get the connection using “CakeDatasourceConnectionManager::get($name)”. $name can be default or any other cases that you have declared. 3. You can also create new connection at run time using config() and get() methods. 4. “ConnectionManager::config('my_connection', $config);
  • 9. Simple CRUD with and without Bootstrap 1. Create Controller with proper naming convention.(XxxsController.php) 2. Create a Model File (XxxTable.php) 3. Create template file (CTP) inside Template (Xxxs/index.ctp) 4. Change default page in routes.php 5. Using Bootstrap, for sample lets see (http://bootswatch.com) 6. Lets check……..
  • 10. Middleware CakePHP provides several middleware few of them are : 1. CakeErrorMiddlewareErrorHandlerMiddleware ( => It traps exceptions from the wrapped middleware and renders an error page using the Error & Exception Handling Exception handler. 1. CakeRoutingAssetMiddleware => It checks the request are are for cake theme or from plugin assets, wheateher its on themes webroot or in plugins webroot
  • 11. Middleware 3. CakeI18nMiddlewareLocaleSelectorMiddleware => It automatically switch language from the Accept-Language header sent by the browsers
  • 12. Deployment 1. To implement the project in 2 or 3 different server, you have to send the codebase through git and rest thing can be done by composer (Composer install or Composer Update). It automatically check the dependencies and folder permission etc. 2. If anyone working on FTP, he has to upload the library manually and have to give the folder permission as expected. 3. You can set the debug mode True/False based on server to server by environment variable in your apache settings.
  • 13. Deployment SetEnv CAKEPHP_DEBUG 1 (In your apache configuration) And then you can set the debug level dynamically in app.php: $debug = (bool)getenv('CAKEPHP_DEBUG'); return [ 'debug' => $debug, ];
  • 14. Deployment 4. To increase your application performance in production once deployment is done through php composer.phar dumpautoload -o After doing this you need set your js/css/images etc path (webroot) through symlink bin/cake plugin assets symlink (This command will symlink your webroot directory)
  • 15. Cache 1. Default CakePHP cache flused once in a year, but you can manage it through config/app.php 2. We can also set the cache for schema description and table listings. 3. We can also flush individual cache if we know the key Cache::delete() will allow you to completely remove a cached object Cache::delete('my_key');
  • 16. Cache 4. If you wish to clear all cache data that may be configured in APC, Memcache etc Cache::clear(true); (Will only clear expired keys.) Cache::clear(false); (Will clear all keys.) 5. We can also use Cache to store/remove common find data. Example :
  • 17. Cache public function postSave($event, $entity, $options = []) { if ($entity->isNew()) { Cache::clearGroup(post, 'home'); } }
  • 18. Cache 6. Enable or Disable Cache globally Cache::disable(); (Disable all cache reads, and cache writes.) Cache::enable(); (Re-enable all cache reads, and cache writes.)
  • 19. Other Important thing 1. You can create your own data type in CakePHP using toPHP, toDatabase, toStatement and marshal, once you are done you can map your Custom data type to SQL expression (https://book.cakephp.org/3.0/en/orm/database- basics.html#CakeDatasourceConnectionManager) 2. In CakePHP DRY(Don’t repeat yourself) is used to allow you to code things once and re-use them across your application. 3. CDN is default configured you can define the path of cdn in configuration
  • 20. Other Important thing 4. How to write custom sql query use CakeDatasourceConnectionManager; $connection = ConnectionManager::get('default'); $results = $connection ->execute('SELECT * FROM articles WHERE id = :id', ['id' => 1]) ->fetchAll('assoc');
  • 21. Other Important thing $connection->insert('articles', [ 'title' => 'A New Article', 'created' => new DateTime('now') ], ['created' => 'datetime']);
  • 22. 5. Create Relationship between Tables Relationship Association Type Example one to one hasOne A user has one profile. one to many hasMany A user can have multiple recipes. many to one belongsTo Many recipes belong to a user. many to many hasAndBelongsToMany Recipes have, and belong to, many ingredients.
  • 23. Example : class IngredientsTable extends Table { public function initialize(array $config) { // have additional data on your IngredientsProducts table $this->belongsToMany('Products', [
  • 24. class ProductsTable extends Table { public function initialize(array $config) { $this->belongsToMany('Ingredients', [ 'through' => 'IngredientsProducts', ]); }
  • 25. class IngredientsProductsTable extends Table { public function initialize(array $config) { $this->belongsTo('Ingredients'); $this->belongsTo('Products'); } }
  • 26. Migration Laravel VS Cakephp Migration needs to be enabled through composer, by default its enabled through the setup Else Plugin::load('Migrations'); in your bootsrap.php file
  • 27. Once you have created in the config/Migrations folder, you will be able to execute the following migrations command to create the table in your database: bin/cake migrations migrate