SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
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
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
     ;-)
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
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
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
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
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
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
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.
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
Baking master class

the practical bit
     http://github.
     com/neilcrookes/CakeFest
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
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
Baking master class

the end
     Thanks for
     listening
     Any questions?
Baking master class

get in touch
     neil@neilcrookes.com
     www.neilcrookes.com
     twitter.com/neilcrookes
     github.com/neilcrookes
     MSN: neil_crookes@hotmail.
     com

Contenu connexe

Dernier

(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607dollysharma2066
 
8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCR8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCRashishs7044
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdfKhaled Al Awadi
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchirictsugar
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menzaictsugar
 
Financial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxFinancial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxsaniyaimamuddin
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaoncallgirls2057
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environmentelijahj01012
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCRashishs7044
 
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCRashishs7044
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Pereraictsugar
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfRbc Rbcua
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?Olivia Kresic
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Riya Pathan
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyotictsugar
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationAnamaria Contreras
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMVoces Mineras
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Servicecallgirls2057
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...ssuserf63bd7
 

Dernier (20)

Corporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information TechnologyCorporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information Technology
 
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
 
8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCR8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCR
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchir
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
 
Financial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxFinancial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptx
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environment
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
 
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Perera
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdf
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyot
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement Presentation
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQM
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...
 

En vedette

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

En vedette (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Baking Master Class

  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Baking master class the practical bit http://github. com/neilcrookes/CakeFest
  • 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. 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. Baking master class the end Thanks for listening Any questions?
  • 15. Baking master class get in touch neil@neilcrookes.com www.neilcrookes.com twitter.com/neilcrookes github.com/neilcrookes MSN: neil_crookes@hotmail. com