25

Slides - Slide 1

  • Upload
    newbu

  • View
    636

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Slides - Slide 1
Page 2: Slides - Slide 1

Your first bite.

Page 3: Slides - Slide 1

Me

• Quick Solutions, Inc.• Microsoft/.NET Developer by day• PHP Developer “on the weekends”• twitter.com/mgroves• mgroves.com• [email protected]

Page 4: Slides - Slide 1

Why PHP?

• Ubiquitous• Open source• 3rd most popular language in the world*• Gentle learning curve (easy to learn)• Cross-platform

*TIOBE http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

Page 5: Slides - Slide 1

What is CakePHP?

CakePHP is an open source MVC (Model-View-Controller) web application framework for producing web applications. It is written in PHP, and modeled after the concepts of Ruby on Rails.

Page 6: Slides - Slide 1

Why MVC?

• Separation of concerns• Testability, maintainability• Structure and elegance• Convention over configuration• A natural fit for the web

Page 7: Slides - Slide 1

JavaScript

HTML

PHP

SQLCSS

Business Logic

Page 8: Slides - Slide 1

Why CakePHP?

• Great community• Well-written documentation• Looks and feels very similar to other MVC

frameworks (like Ruby on Rails, .NET MVC)• Easy to pick up

Page 9: Slides - Slide 1

Start with the model…

• Cake has its own built-in ORM, similar to ActiveRecord

• And it’s similar to Linq-to-SQL in that the database is basically the model

• Conventions

Page 10: Slides - Slide 1

Model Conventions

• Table names in the DB are plural and underscored (blog_posts)

• Class names are singular, CamelCased (BlogPost)• File names are singular, underscored

(blog_post.php)• Primary key should be called ‘id’ and be an int• Foreign keys should be ‘whatever_id’• All these conventions can be ignored, but require

configuration to do so

Page 11: Slides - Slide 1

CakePHP Directory Structure

Page 12: Slides - Slide 1

Tools

• Netbeans IDE– http://www.netbeans.org/

• WampServer– http://www.wampserver.com/en/

• HeidiSQL– http://www.heidisql.com/

Page 13: Slides - Slide 1

Scaffolding Demo

Page 14: Slides - Slide 1

Scaffolding

• Gets us to a working app very quickly (Agile, prototyping, etc) by creating views automatically

• In some cases, scaffolding an entire Administrative area might be acceptable

• But as you might guess, scaffolding gives us no flexibility or customization

• Just like real scaffolding, it's meant to be temporary

Page 15: Slides - Slide 1

Real Views

• Let’s ditch the scaffolding, and create ‘real’ views:– Index (view all blog posts)– View (view a single blog post)– Add (new blog post)– Edit (an existing blog post)– Delete (an existing blog post)

Page 16: Slides - Slide 1

URLs and routing

• Default routing:– /controller/action/first_parameter

• Example:– /blogposts/view/3 – BlogPostsController class, View method, pass 3 to

the first parameter• Routing is configured in /config/routes.php

Page 17: Slides - Slide 1

Views Demo

Page 18: Slides - Slide 1

Testing

• Unit tests are often an important part of building an application, especially a complex one

• One of the benefits of using an MVC framework is separation of concerns

• Separation of concerns allows us to test individual units easier

Page 19: Slides - Slide 1

Testing with CakePHP

• Based on SimpleTest (doesn’t come with CakePHP) - http://simpletest.org/

• Can test different “cases”, like “controllers”, “helpers”, “models”, etc.

• Test methods must start with “test”

Page 20: Slides - Slide 1

Testing Demo

Page 21: Slides - Slide 1

Other CakePHP features

• Relatively mature framework• Contains a rich feature set:– Helpers (JS, Ajax, caching, pagination, etc)– Authorization/authentication components– Model supports relational DB (1-to-many, many-

to-many, etc)– Best feature is simplicity: not a huge framework

filled with esoteric functionality

Page 22: Slides - Slide 1

The future of Cake

• 3 different versions of Cake:– CakePHP 1.x is for PHP4 and up– CakePHP v2 will be for strict PHP5mode, shedding

deprecated stuff, faster– Cake3 has been ‘forked’ into Lithium

• CakePHP2 is available at http://code.cakephp.org/

• Lithium is available at http://li3.rad-dev.org/

Page 24: Slides - Slide 1

Please rate me

• http://speakerrate.com/mgroves

Page 25: Slides - Slide 1