SlideShare ist ein Scribd-Unternehmen logo
1 von 27
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

Weitere Àhnliche Inhalte

Was ist angesagt?

Apache Web server Complete Guide
Apache Web server Complete GuideApache Web server Complete Guide
Apache Web server Complete Guide
webhostingguy
 
Apache Web Services
Apache Web ServicesApache Web Services
Apache Web Services
lkurriger
 
Apache hadoop 2_installation
Apache hadoop 2_installationApache hadoop 2_installation
Apache hadoop 2_installation
sushantbit04
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
backdoor
 

Was ist angesagt? (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
 

Ähnlich wie Cake php

Ähnlich wie 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
 

KĂŒrzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

KĂŒrzlich hochgeladen (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

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