Tutorial CakePHP
Tutorial CakePHP
Marc Fernandez-Girones
INDEX
Framework
Model - View - Controller (MVC)
CakePHP
Simple Use Case
Sample Code
Benets
Limitations
Alternatives
Examples
Resources
FRAMEWORK
Is a set of classes that can be used to perform the more mundane
manipulations of the data in your application.
Is an abstraction in which common code providing generic
functionality can be selectively overridden or specialized by user code
providing specic functionality. - Wikipedia
Is a re-usable design for a software system (or subsystem) that may
include support programs, code libraries, a scripting language, or other
software to help develop and glue together the different components
of a software project. Various parts of the framework may be exposed
through an API. - Creativemediafarm
MODEL - VIEW - CONTROLLER
(MVC)
Controller: Responds to
events, user actions, and
makes requests to the model.
CAKEPHP
Integrated CRUD for database interaction.
Application Scaffolding.
Code Generation via Bake (a console application).
Helpers for HTML, Forms, Pagination, AJAX, Javascript, XML, RSS and more.
Access Control Lists (ACL) and Authentication.
Validation of model data.
Router for mapping URLs and handling extensions.
Email, Cookie, Security, Session and RequestHandler Components.
Internationalization and Localization.
Flexible cache.
SIMPLE USE CASE
CREATING A BLOG
Download: http://cakeforge.org/projects/cakephp/
Bake it!
Source: http://book.cakephp.org/view/219/Blog
SAMPLE CODE
HTML Helper:
<?php echo $html->image('cake_logo.png', array('alt' => 'CakePHP')); ?>
Output: <img src="/img/cake_logo.png" alt="CakePHP" />
<?php echo $html->link('Home Page', '/pages/home', array('target'=>'_blank')); ?>
Output: <a href="/pages/home" target="_blank">Home Page</a>
Form Helper:
<?php echo $form->create('Recipe'); ?>
Output: <form id="RecipeAddForm" method="post" action="/recipes/add">
<?php echo $form->input('title'); ?>
Output: <input name="data[Post][title]" type="text" maxlength="50" value="" id="PostTitle" />
Select:
$this->set('posts', $this->Post->find('all'));
Insert:
$this->Post->save($this->data);
Update:
$this->Post->save($this->data);
Delete:
$this->Post->delete($id);
SAMPLE CODE
BENEFITS
MVC Pattern.
Zero Conguration.
CRUD Scaffolding.
Ajax Support.
ACL Functionality.
Easy to understand.
LIMITATIONS
Zend
Symfony
CodeIgniter
Personal Examples
www.redinter.eu
www.marcfg.com
General Examples
Mozilla Addons
MapMe
Miss Universe
RESOURCES
The Bakery
The Cookbook
CakeDC Team
CakePHP Cheatsheet