Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Slides - Slide 1

924 views

Published on

  • Be the first to comment

  • Be the first to like this

Slides - Slide 1

  1. 1. Your first bite.
  2. 2. Me • Quick Solutions, Inc. • Microsoft/.NET Developer by day • PHP Developer “on the weekends” • twitter.com/mgroves • mgroves.com • webmaster@mgroves.com
  3. 3. 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
  4. 4. 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.
  5. 5. Why MVC? • Separation of concerns • Testability, maintainability • Structure and elegance • Convention over configuration • A natural fit for the web
  6. 6. JavaScript HTML PHP SQL CSS Business Logic
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. CakePHP Directory Structure
  11. 11. Tools • Netbeans IDE – http://www.netbeans.org/ • WampServer – http://www.wampserver.com/en/ • HeidiSQL – http://www.heidisql.com/
  12. 12. Scaffolding Demo
  13. 13. 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
  14. 14. 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)
  15. 15. 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
  16. 16. Views Demo
  17. 17. 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
  18. 18. 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”
  19. 19. Testing Demo
  20. 20. 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
  21. 21. 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/
  22. 22. Resources • http://cakephp.org/ • http://bakery.cakephp.org/articles/view/mod el-based-code-insight-and-completion-in- netbeans (NetBeans code-completion) • http://en.wikipedia.org/wiki/Model–view– controller#PHP • http://cakephpdemo.codeplex.com/ - demo source code • http://www.simpletest.org/
  23. 23. Please rate me • http://speakerrate.com/mgroves

×