ICCM Europe 2013 Presentation: Do you want to build PHP websites faster? I think we all do. In this workshop, we will take a brief look at the CakePHP open-source PHP framework that makes this possible. As we build a simple Twitter like service, called CakeTwit, on the CakePHP Framework, you will learn the benefits of using a framework in your development. CakePHP provides code generation, Model View Controller Architecture, helper libraries for faster development, and much more! If you want make programming a piece of cake, check out this workshop.
3. Missional Digerati
Community of thinkers, designers and developers
committed to leveraging technology to advance the pace
of reaching every person on earth with the good news
of Jesus Christ.
Twitter: @M_Digerati
Github: MissionalDigerati
Website: MissionalDigerati.org
6. Model View Controller
Model - classes that handle business logic of data.
Controller - traffic cop bet ween models and view.
View - renders a presentation of modeled data.
http://goo.gl/yRDaa
7. Convention Over Configuration
DB TABLES MODELS
plural + underscored singular + CamelCased
ex. cars, user_scores ex. Car, UserScore
CONTROLLERS VIEWS
plural + CamelCased + action name +
ending in “Controller” underscored
ex. CarsController, UserScoresController ex. add, view_user
http://goo.gl/N2Nh0
9. <?php
App::uses('AppController', 'Controller');
class TweetsController extends AppController {
public function index() {
/**
* Show All Tweets
*/
}
public function view($id = null) {
/**
* Show an Existing Tweet
*/
}
public function add() {
/**
* Add a New Tweet
*/
}
public function edit($id = null) {
/**
* Edit an Existing Tweet
*/
}
public function delete($id = null) {
/**
* Delete an Existing Tweet
*/
}
}
10. CakeTwit
Development Environments
XP
Mac OSX Lion Windows XP
MAMP 2.1.1 (mamp.info) WAMP 2.2E (wampser ver.com)
PHP 5.4.4 PHP 5.4.3
Apache 2.2.22 Apache 2.2.2
MySQL 5.5.25 MySQL 5.5.24
Sequel Pro (sequelpro.com) PHPMyAdmin 3.5.1
Textmate (macromates.com) Sublime Text (sublimetext.com)
Terminal Command Line
Image by Blog.SpoonGraphics.co.uk & Icons by PinkMoustache.net
11. CakeTwit
Off Screen Preparation
Get CakePHP 2.3 Beta - https://github.com/cakephp/cakephp/tags
Create a Virtual Host
Enable Mod Rewrite
Create a Database
Add PHP to System Path
XP
http://goo.gl/lKoOt http://goo.gl/om8K6
Image by Blog.SpoonGraphics.co.uk & Icons by PinkMoustache.net
13. CakeTwit
Go Green!
NOTICE
Notice (1024): Please change the value of 'Security.salt' in
app/Config/core.php to a salt value specific to your application [CORE/
Cake/Utility/Debugger.php, line 835]
<?php
/**
* File: app/Config/core.php
Change to Random Alphanumeric String
* Line: 187
*/
/**
* A random string used in security hashing methods.
*/
Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
Image by Blog.SpoonGraphics.co.uk
14. CakeTwit
Go Green!
NOTICE
Notice (1024): Please change the value of 'Security.cipherSeed' in
app/Config/core.php to a numeric (digits only) seed value specific to your
application [CORE/Cake/Utility/Debugger.php, line 839]
<?php
/** Change to Random Numeric String
* File: app/Config/core.php
* Line: 192 (Digits Only)
*/
/**
* A random numeric string (digits only) used to encrypt/decrypt strings.
*/
Configure::write('Security.cipherSeed', '76859309657453542496749683645');
Image by Blog.SpoonGraphics.co.uk
15. CakeTwit
Go Green!
NOTICE
Your database configuration file is NOT present.
app/Config/database.php.default app/Config/database.php
Image by Blog.SpoonGraphics.co.uk & Icons by PinkMoustache.net
16. CakeTwit
Go Green!
NOTICE
Your database configuration file is NOT present.
<?php
/**
* File: app/Config/database.php
*/
class DATABASE_CONFIG {
Set Your MySql Settings
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
}
Image by Blog.SpoonGraphics.co.uk
18. CakeTwit
Naming Convention for Tweets
DB TABLE MODEL
t weets Tweet
CONTROLLER
TweetController
Image by Blog.SpoonGraphics.co.uk & Icons by PinkMoustache.net
19. CakeTwit
Tweets Database Table
Import SQL into Database - http://goo.gl/4MHJj
CREATE TABLE `tweets` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`post` varchar(255) DEFAULT NULL,
`author` varchar(255) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `tweets` (`id`, `post`, `author`, `created`, `modified`)
VALUES
(1,'I LUV CakeTwit!!!','A Random Poet','2012-12-24 08:00:00','2012-12-24 08:00:00'),
(2,'Give me another piece of Cake, Twit that is!','Poetic Justice','2012-12-23 08:00:00','2012-12-23 08:00:00');
Image by Blog.SpoonGraphics.co.uk
20. CakeTwit
Bake the Tweet’s Model
XP
In Terminal on Command Line
`cd` into the working directory `cd` into the working directory
> app/Console/cake bake > appConsolecake bake
Select “M” for model Select “M” for model
Follow the interactive console Follow the interactive console
For displayField select post For displayField select post
Add a validation to post as Add a validation to post as
“notempty” “notempty”
Image by Blog.SpoonGraphics.co.uk & Icons by PinkMoustache.net
21. CakeTwit
Bake the Tweet’s Controller
XP
In Terminal on Command Line
`cd` into the working directory `cd` into the working directory
> app/Console/cake bake Controller > appConsolecake bake Controller
Follow the interactive console Follow the interactive console
Build the controller Build the controller
interactively interactively
No dynamic scaffolding No dynamic scaffolding
Use basic class methods Use basic class methods
Image by Blog.SpoonGraphics.co.uk & Icons by PinkMoustache.net
22. CakeTwit
Bake the Tweet’s Views
XP
In Terminal on Command Line
`cd` into the working directory `cd` into the working directory
> app/Console/cake bake View > appConsolecake bake View
Follow the interactive console Follow the interactive console
Image by Blog.SpoonGraphics.co.uk & Icons by PinkMoustache.net
23. The Real Van Gogh
Visit your local website, and see your master piece!
Image by DryIcons.com
25. Model DataSource Data
DataSources
The link bet ween models and the source of data that models represent.
MySql Sqlite Postgres Sqlserver
Icons by PinkMoustache.net & DefaultIcon.com
http://goo.gl/dXzjq
26. Models Behavior
Behaviors
Reusable logic for the models. A mixin with callbacks.
Access Control List Translate
Containable Tree
Icons by PinkMoustache.net
http://goo.gl/17M6G + http://goo.gl/44OhY
27. Controllers Components
Components
Reusable logic for controllers.
Security Cookies
Sessions Authentication
Access Control Lists Request Handling
Emails Pagination
Icons by PinkMoustache.net
http://goo.gl/Mp2NO + http://goo.gl/i53PM
28. Views
Elements
Layouts Helpers
Helpers
Presentational logic shared among views, elements, and layouts.
Cache Pagination Text
(Paginator)
Form Time
HTML RSS
Javascript (JS) Session
Icons by PinkMoustache.net
http://goo.gl/8Gl8c + http://goo.gl/F2Ju5