2. Who am I
• Brad Hancock
• Twitter @braddhancock
• braddhancock@gmail.com
• Network Security Engineer
• Part-time CakePHP developer.
3. Goals for tonight
• Identify Cake.
• To demonstrate CakePHP’s ability to rapidly
deploy an application.
• Build an application in under 1 hour.
4. What is CakePHP
• Free open-source rapid development framework.
• MVC Architecture.
• Application scaffolding.
• Code Generation.
• Convention over configuration.
5. Steps for prototyping an Application in
CakePHP
• LAMP Installation.
Linux Apache Mysql & PHP
• Build the database.
• Bake the application.
Just that easy
• Run the application.
6. Pre-configuration
Apache 2.2 Web server needs modrewrite enabled
# a2enmod rewrite (debian)
Mysql
Latest CakePHP 1.3 installation from
CakePHP.
7. Steps
• Extract Cake to your apache document root.
• Test that the framework starts.
• Ensure rewrite is enabled.
• Create your database -- mysql
• Create the database tables.
tables names plural
foreign key columns named as tablename_id
(convention over configuration)
8. Bake time.
• ../cake/console/cake bake project – create salt
Hashing in Cake defaults to Sha1. The Salt prevents dictionary attacks on the hash.
• ../cake/console/cake bake db_config -create db con.
Connect Cake to MySQL
• ../cake/console/cake bake model all --models
• ../cake/console/cake bake controller all --controllers
• ../cake/console/cake bake view all -- views
9. See the application
• Automatic generation of CSS and HTML for views.
• Notice associations are automatically created based
on column names.
• Notice Friendly URLs.
10. Validation and Automatic creation of
Form fields.
• Based on user input we can bake model
validation right into the application.
• Quickly rebuilding our model and view if
necessary.
11. Enable Auth Component
• Create User Table
– Must have username and password columns.
– Password Type must be Varchar(40) for hash.
CREATE TABLE users (
id integer auto_increment,
username char(50),
password char(40),
admin int(1),
PRIMARY KEY (id));
12. Add a user and create login view
• Bake the Model, Controller, & View.
• var $components = array('Auth', 'Session');
– Add to the App_Controller.php Parent Controller for all
others.
Modify the User Controller to add the Login and logout
method.
13. Modify the User Controller
class UsersController extends AppController {
var $name = 'Users';
function beforeFilter() {
$this->Auth->allow('*');
}
function login() {
}
function logout() {
$this->redirect($this->Auth->logout());
}
}
15. Customize your app
• Build a menu or modify your opening page.
– app/views/pages/home.ctp
• Modify the CSS styles.
– app/webroot/css
• Customize your views, controllers, &models
– app/views, app/controllers, app/models
16. Learning More
• book.cakephp.org website cookbook
• Books:
– Beginning CakePHP:From Novice to Professional
David Golding. Kindle $18. On Cake 1.2
- Super Awesome Advanced CakePHP tips
Matt Curry. Free www.pseudocoder.com
- CakePHP 1.3 Application Development Cookbook
Mariano Iglesias
• IRC:
– Freenode channel #cakephp
17. IRC
<Ceeram> what do you mean with this then?:
<kidtangerine> he adds public in front of his
functions
> Does that have a question mark on the
end, asshole?
Notes de l'éditeur
Describe Framework A framework is collection of libraries, all ready setup to do the generic functions of an application. It provides pre-existing code so you can focus on the logic of your program.Descrbe Rapid Development Framework. A framework focused on creating applications quickly.Describe MVC Architecture Model – Talks to the database View – HTML, Users sees Controller – Regulates between the two. All files are organized between these components. Makes things very organized. Bank anology: Safe is the database, and only the bankers (models) are allowed in there. Bankers are fat and lazy but make most of decisions. The tellers (controllers) take all the info from the customers (views). The bankers never talk to the customer, they are too good for that, they let the tellers bring the information back and forth to the idiot customers. Convention over Configure, has to do with how things are named in the framework, by naming things in a certain syntax or notation Cake can use those names to preconfigured the application. We will discuss convention over configuration in naming tables and columns for our mysql db. Why use MVC? Because it is a tried and true software design pattern that turns an application into a maintainable, modular, rapidly developed package. Crafting application tasks into separate models, views, and controllers makes your application very light on its feet. New features are easily added, and new faces on old features are a snap. The modular and separate design also allows developers and designers to work simultaneously, including the ability to rapidly prototype. Separation also allows developers to make changes in one part of the application without affecting others.If you've never built an application this way, it takes some time getting used to, but we're confident that once you've built your first application using CakePHP, you won't want to do it any other way.
To rapidly deploy an application in cake, first we need to build the database and all of its tables. Does anyone not familiar with LAMP.
Unzip –dmemphisphp cake.1.3.zipMv ./memphisphp/cake/* ./memphisphp/(convention over configuration)You need to create your database first. All table names are plural. members, member_details, and member_skillsYou want to use InnoDB due to CakePHP only supporting transactions with that engine. ~$ mysql -u root -pPaste fileTalk briefly about db setup and phpmyadmin
Cake has libraries for built in hashing of passwords for its Auth Component. It can support Sha2 256and MD5 Show what the cake bake looks like without all.
var $components = array('Auth', 'Session'); Actual code for the controller. Need to test.
Add the customize method in the user controller. Add beforeFilter() { $this->Auth->allow(‘add’); }
Generates our HTML output on the next slide. Form Helper.