Baking Master Class

2,072
-1

Published on

Slides from the talk given by Neil Crookes during the CakeFest #3 - July 2009

Note: the original pdf and the code related to this talk can be found on cakephp.org (http://cakephp.org/downloads/CakeFest/CakeFest%203%20-%20Berlin%202009/Neil%20Crookes%20-%20Bake%20Master%20Class)

Published in: Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,072
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Baking Master Class

  1. 1. Baking master class who am i? Neil Crookes Southampton, UK MEng Electronic Engineering 2001 Married Helen 2004 Daughter Charlotte born May 2007 Kid #2 due September 2009 Senior Programmer @ Five by Five (Digital media agency) LAMP 8 years CakePHP 3 years
  2. 2. Baking master class the plan... Intro to Bake How does it work? Customising view templates Extending core shell and tasks Start with the theory... Sorry Step by step practical examples All code available... Shortly... Hopefully with history too Demonstrate the awesome power of bake Encourage you to write your own extensions... And share them with me ;-)
  3. 3. Baking master class intro to bake Console script Collection of a shell, several tasks and templates Code generation <?php echo “<?php echo $html->link(‘Master baker’, ‘http://neilcrookes.com’); ?>n”; ?> Great for admin... But less likely you’ll use it for front end http://book.cakephp.org/view/108/The-CakePHP-Console http://book.cakephp.org/view/113/Code-Generation-with-Bake http://cakephp.org/screencasts/view/6
  4. 4. Baking master class how does it work? Bake shell /cake/console/libs/bake.php Tasks /cake/console/libs/tasks Project DbConfi g Model * Controll er * View * Plugin /cake/console/libs/templates/views Test Templates Form * Home Index * View
  5. 5. Baking master class the bake shell Extends Shell Prompts user for “thing” to bake, calls execute() on “thing” task bake all Bakes project if specifying a dir that does not exist in root Bakes database.php if does not exist in app/config bake help
  6. 6. Baking master class ModelTas k Also Extends Shell execute() – Calls __interactive() or bake() depending on args listAll() – Lists all available models based on db tables getName() – Prompts user to select one to bake __interactive() – Checks table name, primary key etc, confirms selections back to user doValidation() – * Prompts for a validation rule for each field doAssociations() – Prompts for associations bake() – Constructs strings of PHP code & writes to model file bakeTest() – bakes the model test case fixture() – bakes the model test fixtures for the model test case
  7. 7. Baking master class ControllerTas k Also Extends Shell execute() – Calls __interactive() or bake() & bakeActions() depending on args listAll() – Lists all available controllers getName() – Prompts user to select one to bake __interactive() – Prompts for scaffold/actions, admin actions, sessions, components, helpers etc, confirms selections back to user bakeActions() – Constructs string of PHP code for CRUD actions bake() – Constructs strings of PHP code & writes to controller file bakeTest() – bakes the controller test case
  8. 8. Baking master class ViewTas k Also Extends Shell execute() – Calls __interactive() or bake() depending on args __interactive() – Prompts for scaffold actions, admin actions, confirms selections back to user __loadController() – Prepares variables to be available in the view templates such as $pluralHumanName etc __associations() – Prepares associations variable to be available in the view templates, used for determining which actions are required etc getContent() – uses output buffering around include() to get the processed contents of the template bake() – Writes content to view file
  9. 9. Baking master class index view template HTML with bit of PHP in the middle Normal PHP code gets interpreted by include() so if you want PHP code in your views, you have to echo “<?php $code; ?>”; Uses vars from __loadController() Loops through fields in the model printing table headings and cells If field is a belongsTo foreignKey, makes it a link to view that record Prints action links at the end of each table row Prints pagination helper code Loops through associations printing links to add and list associated model records.
  10. 10. Baking master class form view template Shared by add & edit views Loops through fields in the model and HABTM associations printing $form->input() Prints link to index and delete record if edit view Loops through associations printing links to add and list associated model records. Admin views use the same template as non-admin
  11. 11. Baking master class the practical bit http://github. com/neilcrookes/CakeFest
  12. 12. Baking master class what to do to make it more awesome? Add markup & CSS hooks for your admin stylesheet Ignore certain fields in views Make views more DRY Bake individual templates Bake templates for multiple controllers Bake multiple controllers Make baked files use your own behaviors, components, helpers & elements Bake multiple validation rules per field Enhance usability, e.g. post save redirects, nicer error messages, format times
  13. 13. Baking master class what to do to make it even more awesome? Loads of UI widgets, e.g. File upload progress bars, date pickers, rich text editors, drag and drop re-ordering Link if permission – integrate ACL Filter functionality on index views Breadcrumbs and browse on hierarchical model index views Ajax validation Abstract controller logic to AppController Modal add forms linked from select boxes for belongsTo foreignKey fields ... And probably lots more
  14. 14. Baking master class the end Thanks for listening Any questions?
  15. 15. Baking master class get in touch neil@neilcrookes.com www.neilcrookes.com twitter.com/neilcrookes github.com/neilcrookes MSN: neil_crookes@hotmail. com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×