Upload
vikaspt9
View
233
Download
0
Embed Size (px)
Citation preview
8/14/2019 Tech Talk - Cakephp
1/25
Programming in PHP
Have you Cake?
8/14/2019 Tech Talk - Cakephp
2/25
Agenda
Introduction
Components needed
Model-View-ControllerCake convention
Relationship between Models
Validation of dataBaking the cake
Hands on
Conclusion
8/14/2019 Tech Talk - Cakephp
3/25
Introduction
Rapid development framework for PHP
Using design patterns: MVC and ORM
Similar to Zend and Ruby on Rails (ROR)framework
Scaffolding support - 2 line code for CRUD
Easier to maintain
Reduces development costs
Write less code
Current version (Stable: 1.1.19.6305)
8/14/2019 Tech Talk - Cakephp
4/25
Introduction (cont)
Example of sites done using CakePHPhttp://ping.sg
http://www.yaledailynews.com
http://scratch.mit.edu/
http://store.theonion.com/
8/14/2019 Tech Talk - Cakephp
5/25
8/14/2019 Tech Talk - Cakephp
6/25
Model-view-controller
In short MVC
Multi-tier architecture
Decoupling of program Business logic Data presentation User interaction
Benefits reduce complexity in architectural design increase flexibility and reuse.
8/14/2019 Tech Talk - Cakephp
7/25
Model-View-Controller (cont)
Model domain-specific representation of the information
View Renders the model into a form suitable for
interaction
Controller
Processes and responds to events
To make use of this capability, conventionneeds to be followed
8/14/2019 Tech Talk - Cakephp
8/25
Convention - Filename
Controller KissesAndHugsController ->
kisses_and_hugs_controller.php
Model OptionValue -> option_value.php
Component
MyHandy -> my_handy.phpHelper BestHelperEver -> best_helper_ever.php
8/14/2019 Tech Talk - Cakephp
9/25
Convention - Model
Model class names are singular
Capitalized for single-word models
Person, MonkeyUpperCamelCased for multi-word models. GlassDoor, LineItem, ReallyNiftyThing
many-to-many join tables tags_users
Model filenames use a lower-caseunderscored syntax
person.php, line_item.php, really_nifty_thing.php
8/14/2019 Tech Talk - Cakephp
10/25
Convention - Model
Database tables plural, lower-case
underscored syntaxpeople, monkeys, glass_doors, line_items,
really_nifty_things
8/14/2019 Tech Talk - Cakephp
11/25
Example of model file - school.php
8/14/2019 Tech Talk - Cakephp
12/25
Convention - Controller
Class names are plural
Capitalized for single-word controllers, and
UpperCamelCased for multi-word controllers.Controller file names use a lower-case
underscored syntax
For protected member visibility, controlleraction names should be prepended with '-.
For private member visibility, controller actionnames should be prepended with '__'.
8/14/2019 Tech Talk - Cakephp
13/25
Example of controller -
schools_controller.php
8/14/2019 Tech Talk - Cakephp
14/25
Convention (more)
More convention for cakeHelpers
Vendors
Components
8/14/2019 Tech Talk - Cakephp
15/25
Convention - Views
Named after actions they display.
Name the view file after action name, in
lowercase.
You can force an action to render aspecific view by calling
$this->render(create'); at the end of youraction.
8/14/2019 Tech Talk - Cakephp
16/25
Model Relationship
3 types of relationship between modelHas One
Has Many
Has And Belong To Many (HATBM)
8/14/2019 Tech Talk - Cakephp
17/25
Built-in validation for data
VALID_NOT_EMPTY
VALID_EMAIL
VALID_NUMBER
VALID_YEAR
Regex allowed
8/14/2019 Tech Talk - Cakephp
18/25
Baking cake
Create class files of model, controller and viewfiles effortlessly
Automate the creation of model class, validationfor attributes and relationship. Able to bake controllers and views. Run terminal window to execute bake script. Steps
Go to place where you can to create the application viacd command
/usr/bin/php {cakehome}/scripts/bake.php -help
8/14/2019 Tech Talk - Cakephp
19/25
Setting up cake
Copy and paste into wwwroot or htdocs
8/14/2019 Tech Talk - Cakephp
20/25
Schools table
CREATE TABLE `learncake`.`schools` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDBAUTO_INCREMENT=4 DEFAULT
CHARSET=utf8;
8/14/2019 Tech Talk - Cakephp
21/25
Students table
CREATE TABLE `learncake`.`students` (
`id` int(11) NOT NULL auto_increment,
`matric` int(11) NOT NULL,
`nric` int(11) NOT NULL,`name` varchar(65) NOT NULL,
`yrentered` int(11) NOT NULL,
`password` varchar(20) NOT NULL,
`school_id` int(11) default NULL,PRIMARY KEY (`id`),
CONSTRAINT `schoolfk` FOREIGN KEY (`school_id`)REFERENCES `schools` (`id`)
ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT
CHARSET=utf8;
8/14/2019 Tech Talk - Cakephp
22/25
Hands On
8/14/2019 Tech Talk - Cakephp
23/25
Conclusion
Easy to use
Quick implementation
Quick to deploy
Free =)
Once you use it, you want more of it
8/14/2019 Tech Talk - Cakephp
24/25
Any Question?
8/14/2019 Tech Talk - Cakephp
25/25
Recommended links
cakephp.org
cakelive.net
php.net
apachefriends.org/en/xampp.html
Download slides plaktoz.com/misc/learncake.zip