SlideShare ist ein Scribd-Unternehmen logo
1 von 26
CakePHP
CakePHP
• A framework for developing applications in
PHP
• Inspired by Ruby on Rails
• Follows MVC design pattern
• Convention over configuration
– No wheel reinventing required!
MVC
• Model
– Data layer

• View
– Presentation layer

• Controller
– Logic layer
CakePHP Framework
• app/
•
•
•
•
•
•
•
•

config/
controllers/
models/
plugins/
tmp/
vendors/
views/
webroot/

• cake/
• config/
• docs/
• libs/

• vendors/
Naming conventions
• http://book.cakephp.org/view/328/CakeConventions
• Table names: “notes”, “my_notes”
• Model: “mynote.php”->“MyNote”
• Controller: “my_notes_controller.php”->
“MyNotesController”
• Views named after actions, organised in folders
according to the related controller:
– views/my_notes/index.thtml
– views/my_notes/add.thtml
Paths + parameters
• Cake uses url to pass parameters
• Apache mod_rewrite converts url into
scriptname and parameters
• http://www.example.com
/controllername/action/param1/param2/…
• Uses paths to figure out views
• Views stored in “controllername” folder
OOP in PHP
• Limited support in PHP <5
• Much better support in PHP >=5
• Simpler than Java OOP
class SomeClass {
function func() {
….
}
}
SomeClass s = new someClass();
s->func();
Hello world… again
• Remember application is separated into
model / view / controller
• Model:
<?php
/* /app/model/hello.php */
class Hello extends AppModel {
var $name

= 'Hello';

var $useTable = false;
}
?>
Hello world… again
• View:
<!-/* /app/views/index.thtml */
-->
<hr size=1/>
<h1><?php echo $data ?></h1>
<hr size=1/>
• Controller:
<?php
/* app/controller/hello_controller.php */
class HelloController extends AppController {
var $name = "Hello";
var $uses = 'Hello';
function index() {
$data = 'Hello world!';
$this->set('data', $data);
}
}
?>
Simple DB table app
• An online contact list
• We want to add, edit, view and delete
names and phone numbers
• Uses a single table
Model
• Add table to DB:
CREATE TABLE cake_contacts (
id INT UNSIGNED AUTO_INCREMENT
PRIMARY KEY,
name VARCHAR(50),
number VARCHAR(50),
created DATETIME DEFAULT NULL,
modified DATETIME DEFAULT NULL
);
Model
• Add a script called contact.php to models/
<?php
class Contact extends AppModel
{
var $name = ‘Contact';
}
?>
View
• views/contacts/index.thtml
<h1>Contact list</h1>
<p>
<?php echo $html->link('Add Contact',
'contacts/add') ?>
</p>
<table>
<tr>
<th>Id</th>
<th>Name</th>
<th>Number</th>
</tr>
View

• views/contacts/index.thtml cntd…

<?php foreach ($contacts as $contact): ?>
<tr>
<td><?php echo $contact['Contact']['id']; ?></td>
<td>
<?php
echo $html->link($contact['Contact'][name'],
"contacts/view/{$contact['Contact']['id']}")?>
[<?php echo $html->link('Edit',
"contacts/edit/{$contact['Contact']['id']}")?>,
<?php echo $html->link('Delete',
"contacts/delete/{$contact['Contact']['id']}",
null, 'Sure?')?>]
</td>
<td><?php echo $contact['Contact']['created']; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
View
• views/contacts/view.thtml
<h1><?php echo $data['Contact']
['name']?></h1>
<p><small>
Created: <?php echo $data['Contact']
['created']?>
</small></p>
<p><?php echo $data['Contact']
['number']?></p>
View
• views/contacts/add.thtml
<h1>Add Contact</h1>
<form action="<?php echo $html->url("contacts/add"); ?
>" method="post">
<p>Name:
<?php echo $html->input('Contact/name',
array('size' => '40')) ?>
</p>
<p>Number:
<?php echo $html->input('Contact/number',
array('size' => '40')) ?>
</p>
<p><?php echo $html->submit('Save') ?>
</p>
</form>
View

• views/contacts/edit.thtml
<h1>Edit Contact</h1>
<form action="<?php echo $html->url('/contacts/edit')?
>" method="post">
<?php echo $html->hidden('Contact/id'); ?>
<p>Name:
<?php echo $html->input('Contact/name',
array('size' => '40')) ?>
</p>
<p>Number:
<?php echo $html->input('Contact/number',
array('size' => '40')) ?>
</p>
<p>
<?php echo $html->submit('Save') ?>
</p>
</form>
Controller
• /app/controllers/notes_controller.php:
<?php
class ContactsController extends AppController
{
var $name = 'Contacts';
function index() {
$this->set('contacts', $this->Contact>findAll());
}
function view($id) {
$this->Contact->id = $id;
$this->set('data', $this->Contact->read());
}
Controller
•

/app/controllers/notes_controller.php:
function add() {
if (!empty($this->data['Contact'])) {
if($this->Contact->save($this->data['Contact'])) {
$this->flash('Your contact has been added.',
‘/contacts/');
}
}
}
function delete($id) {
if ($this->Contact->del($id)) {
$this->flash('The contact with id: '.$id.' has been
deleted.', ‘/contacts/');
}
}
Controller
•

/app/controllers/notes_controller.php:
function edit($id = null) {
if (empty($this->data['Contact'])) {
$this->Contact->id = $id;
$this->data = $this->Contact->read();
} else {
if($this->Contact->save($this->data['Contact'])) {
$this->flash('Your contact has been
updated.',‘/contacts/');
}
}
}

}
?>
Resulting application

…../cake/contacts/add

…../cake/contacts/edit/1

…../cake/contacts/view/4
Other benefits
• Bake script – command line script generator
• Uses LAMP common web platform
– (Linux, Apache, MySQL and PHP)

• Helpers for HTML, Forms, Pagination,
AJAX, Javascript, XML, RSS
• Scaffolding (no need for views)
– Create controller with var $scaffold;
Disadvantages
• Mainly due to the limitations of PHP
– Clumsy OOP
– Access data through arrays not classes (which
RoR does) – more code in view

• Create tables in separate SQL
• Not well documented yet

Weitere ähnliche Inhalte

Was ist angesagt?

OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
 
HTML5 - The 2012 of the Web - Adobe MAX
HTML5 - The 2012 of the Web - Adobe MAXHTML5 - The 2012 of the Web - Adobe MAX
HTML5 - The 2012 of the Web - Adobe MAX
Robert Nyman
 
Spca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesSpca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_libraries
NCCOMMS
 
PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014
cagataycivici
 
Validation using javascripts by karan chanana
Validation using javascripts by karan chananaValidation using javascripts by karan chanana
Validation using javascripts by karan chanana
karan info
 
JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)
Roger Kitain
 

Was ist angesagt? (20)

Engines: Team Development on Rails (2005)
Engines: Team Development on Rails (2005)Engines: Team Development on Rails (2005)
Engines: Team Development on Rails (2005)
 
Django Bogotá. CBV
Django Bogotá. CBVDjango Bogotá. CBV
Django Bogotá. CBV
 
The Chaos Tools Suite
The Chaos Tools SuiteThe Chaos Tools Suite
The Chaos Tools Suite
 
Ch9 .Best Practices for Class-Based Views
Ch9 .Best Practices  for  Class-Based ViewsCh9 .Best Practices  for  Class-Based Views
Ch9 .Best Practices for Class-Based Views
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
Building custom APIs
Building custom APIsBuilding custom APIs
Building custom APIs
 
PHP & MVC
PHP & MVCPHP & MVC
PHP & MVC
 
HTML5 - The 2012 of the Web - Adobe MAX
HTML5 - The 2012 of the Web - Adobe MAXHTML5 - The 2012 of the Web - Adobe MAX
HTML5 - The 2012 of the Web - Adobe MAX
 
Spca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesSpca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_libraries
 
PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014
 
crtical points for customizing Joomla templates
crtical points for customizing Joomla templatescrtical points for customizing Joomla templates
crtical points for customizing Joomla templates
 
Validation using javascripts by karan chanana
Validation using javascripts by karan chananaValidation using javascripts by karan chanana
Validation using javascripts by karan chanana
 
Leveraging the Chaos tool suite for module development
Leveraging the Chaos tool suite  for module developmentLeveraging the Chaos tool suite  for module development
Leveraging the Chaos tool suite for module development
 
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
 
RESTful Web Development with CakePHP
RESTful Web Development with CakePHPRESTful Web Development with CakePHP
RESTful Web Development with CakePHP
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
 
Slimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en TruuksSlimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en Truuks
 
JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)
 
MVC Frameworks for building PHP Web Applications
MVC Frameworks for building PHP Web ApplicationsMVC Frameworks for building PHP Web Applications
MVC Frameworks for building PHP Web Applications
 
Web development today
Web development todayWeb development today
Web development today
 

Andere mochten auch

Andere mochten auch (9)

Cultural Implications Grogent 14
Cultural Implications Grogent 14Cultural Implications Grogent 14
Cultural Implications Grogent 14
 
Legal Foundation
Legal Foundation Legal Foundation
Legal Foundation
 
Power Point Chapter Three
Power Point Chapter ThreePower Point Chapter Three
Power Point Chapter Three
 
Consent Decree Power Point
Consent Decree Power PointConsent Decree Power Point
Consent Decree Power Point
 
Power Point Chapter Three
Power Point Chapter ThreePower Point Chapter Three
Power Point Chapter Three
 
Consent Decree Florida
 	Consent Decree Florida  	Consent Decree Florida
Consent Decree Florida
 
Power Point Chapter Two
Power Point Chapter TwoPower Point Chapter Two
Power Point Chapter Two
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
Power Point Chapter Three
Power Point Chapter ThreePower Point Chapter Three
Power Point Chapter Three
 

Ähnlich wie Language literacy

MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
Dilip Patel
 
phpWebApp presentation
phpWebApp presentationphpWebApp presentation
phpWebApp presentation
Dashamir Hoxha
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
Kevin Wu
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 

Ähnlich wie Language literacy (20)

Synapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephpSynapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephp
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
cake phptutorial
cake phptutorialcake phptutorial
cake phptutorial
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
C# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASPC# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASP
 
Ei cakephp
Ei cakephpEi cakephp
Ei cakephp
 
Cakeph pppt
Cakeph ppptCakeph pppt
Cakeph pppt
 
phpWebApp presentation
phpWebApp presentationphpWebApp presentation
phpWebApp presentation
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
 
Language Basics | Coldfusion primer | Chap-1
Language Basics | Coldfusion primer | Chap-1Language Basics | Coldfusion primer | Chap-1
Language Basics | Coldfusion primer | Chap-1
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend Framework
 
Building Modern Websites with ASP.NET by Rachel Appel
Building Modern Websites with ASP.NET by Rachel AppelBuilding Modern Websites with ASP.NET by Rachel Appel
Building Modern Websites with ASP.NET by Rachel Appel
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 

Mehr von Sanjulika Rastogi (20)

Using Proficiency Testing
Using Proficiency Testing Using Proficiency Testing
Using Proficiency Testing
 
WIDA CELLA
WIDA CELLAWIDA CELLA
WIDA CELLA
 
Using Proficiency Testing
Using Proficiency Testing Using Proficiency Testing
Using Proficiency Testing
 
Using Proficiency Testing
Using Proficiency Testing Using Proficiency Testing
Using Proficiency Testing
 
WIDA CELLA
WIDA CELLAWIDA CELLA
WIDA CELLA
 
Methods-Building Developmental Lessons
Methods-Building Developmental LessonsMethods-Building Developmental Lessons
Methods-Building Developmental Lessons
 
SLA Theories-Chapter 6
SLA Theories-Chapter 6SLA Theories-Chapter 6
SLA Theories-Chapter 6
 
Language Experience Lesson Activity
Language Experience Lesson ActivityLanguage Experience Lesson Activity
Language Experience Lesson Activity
 
Cooperative Learning Activity
Cooperative Learning ActivityCooperative Learning Activity
Cooperative Learning Activity
 
ganesh testing
ganesh testing ganesh testing
ganesh testing
 
ganesh testing
ganesh testing ganesh testing
ganesh testing
 
Test resource 2
Test resource 2Test resource 2
Test resource 2
 
Pop Tart Cat 3
Pop Tart Cat 3Pop Tart Cat 3
Pop Tart Cat 3
 
Resource Erin
Resource ErinResource Erin
Resource Erin
 
Resource Erin
Resource ErinResource Erin
Resource Erin
 
Test resource 2
Test resource 2Test resource 2
Test resource 2
 
Pop Tart Cat 3
Pop Tart Cat 3Pop Tart Cat 3
Pop Tart Cat 3
 
Pop Tart Cat 3
Pop Tart Cat 3Pop Tart Cat 3
Pop Tart Cat 3
 
Test resource 2
Test resource 2Test resource 2
Test resource 2
 
Resource Erin
Resource ErinResource Erin
Resource Erin
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
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
 

Language literacy