SlideShare a Scribd company logo
The Mystery In The Models
Adding a Model to Your EE Add-on
Current Pittsburgher
I lead tripleNERDscore
I build in EE
I love my fam
I drink more coffee than I should
I’m here to serve!
Models Made Me Wanna….
What Are Models
And
What Do They Do?
How EE Uses Models
Create an Entry
system/ee/EllisLab/ExpressionEngine/Controller/Publish/Publish.php
Read a Member
system/ee/EllisLab/ExpressionEngine/Controller/Members/Members.php
Get a File and Filter on Relationship
system/ee/EllisLab/ExpressionEngine/Controller/Files/Files.php
Let’s Build!
Create Our Data Structure
Data Structure
Model: Vote
Table: upvotedownvote_votes
id - our primary key
entry_id - Associated entry
upvotes - Count of upvotes
downvotes - Count of upvotes
Initiate Our Model
Initiate Our Model
Scaffold Our Model
Let's Make it CRUDdy
What Else Can Models Do?
Relationships
Events
Validation
Metadata
Many to Many Relationships
Collections
Helpful Links:
https://docs.expressionengine.com/latest/development/services/model.html
https://codeigniter.com/userguide3/database/forge.html
https://github.com/dougblackjr/eeconf-presentation
https://github.com/dougblackjr/upvotedownvote
My Stuff
https://triplenerdscore.net
https://ee-addon-generator.triplenerdscore.xyz
twitter: @dougblackjr
Questions?

More Related Content

Similar to The Mystery In The Models: The Basics of Adding a Model to your EE Add-on

Online Testing Learning to Rank with Solr Interleaving
Online Testing Learning to Rank with Solr InterleavingOnline Testing Learning to Rank with Solr Interleaving
Online Testing Learning to Rank with Solr Interleaving
Sease
 
SharePoint Lists: Used, Abused and Underappreciated
SharePoint Lists: Used, Abused and UnderappreciatedSharePoint Lists: Used, Abused and Underappreciated
SharePoint Lists: Used, Abused and Underappreciated
Wes Preston
 
Building Forio Web Simulations - Introduction to Interface Design
Building Forio Web Simulations - Introduction to Interface DesignBuilding Forio Web Simulations - Introduction to Interface Design
Building Forio Web Simulations - Introduction to Interface Designforiocorp
 
ASAE Tech: Data Data Everywhere
ASAE Tech: Data Data EverywhereASAE Tech: Data Data Everywhere
ASAE Tech: Data Data Everywheremjgoldsmith
 
Get a Little Help with Your Help Desk Application
Get a Little Help with Your Help Desk ApplicationGet a Little Help with Your Help Desk Application
Get a Little Help with Your Help Desk ApplicationIron Speed
 
Essay Writing Service Reviews Top 10 Best Pap
Essay Writing Service Reviews Top 10 Best PapEssay Writing Service Reviews Top 10 Best Pap
Essay Writing Service Reviews Top 10 Best Pap
Amber Wheeler
 
Trigger Emails BigD17
Trigger Emails BigD17Trigger Emails BigD17
Trigger Emails BigD17
Susan McKenzie
 
Pratical Deep Dive into the Semantic Web - #smconnect
Pratical Deep Dive into the Semantic Web - #smconnectPratical Deep Dive into the Semantic Web - #smconnect
Pratical Deep Dive into the Semantic Web - #smconnect
Jan-Willem Bobbink - Freelance SEO Consultant
 
Office 365 Productivity Tips "May Mediation"
Office 365 Productivity Tips "May Mediation"Office 365 Productivity Tips "May Mediation"
Office 365 Productivity Tips "May Mediation"
Christian Buckley
 
Ignite pitch
Ignite pitchIgnite pitch
Ignite pitch
Devon Smith
 
Ruby on Rails Plugins - Rich Collins
Ruby on Rails Plugins - Rich CollinsRuby on Rails Plugins - Rich Collins
Ruby on Rails Plugins - Rich Collins
Rich Collins
 
Cyber Threats and Data Privacy in a Digital World
Cyber Threats and Data Privacy in a Digital WorldCyber Threats and Data Privacy in a Digital World
Cyber Threats and Data Privacy in a Digital World
qubanewmedia
 
Improving Spreadsheet Test Practices
Improving Spreadsheet Test PracticesImproving Spreadsheet Test Practices
Improving Spreadsheet Test Practices
Felienne Hermans
 
JDO 2019: Data Science for Developers - Matthew Renze
JDO 2019: Data Science for Developers -  Matthew RenzeJDO 2019: Data Science for Developers -  Matthew Renze
JDO 2019: Data Science for Developers - Matthew Renze
PROIDEA
 
How to design with science and not destroy the magic
How to design with science and not destroy the magicHow to design with science and not destroy the magic
How to design with science and not destroy the magic
Joe Leech
 
How to design with science: and not destroy the magic (Joe Leech)
How to design with science: and not destroy the magic (Joe Leech)How to design with science: and not destroy the magic (Joe Leech)
How to design with science: and not destroy the magic (Joe Leech)
Future Insights
 
Sydney Salesforce NFP user group july 2011
Sydney Salesforce NFP user group july 2011Sydney Salesforce NFP user group july 2011
Sydney Salesforce NFP user group july 2011
Kevin Akermanis
 
Becoming a Power User
Becoming a Power UserBecoming a Power User
Becoming a Power User
EverettProgram
 
Data Data Everywhere: Drowning in a Sea of Analytics
Data Data Everywhere: Drowning in a Sea of AnalyticsData Data Everywhere: Drowning in a Sea of Analytics
Data Data Everywhere: Drowning in a Sea of Analytics
Megan Denhardt
 

Similar to The Mystery In The Models: The Basics of Adding a Model to your EE Add-on (20)

Online Testing Learning to Rank with Solr Interleaving
Online Testing Learning to Rank with Solr InterleavingOnline Testing Learning to Rank with Solr Interleaving
Online Testing Learning to Rank with Solr Interleaving
 
SharePoint Lists: Used, Abused and Underappreciated
SharePoint Lists: Used, Abused and UnderappreciatedSharePoint Lists: Used, Abused and Underappreciated
SharePoint Lists: Used, Abused and Underappreciated
 
Building Forio Web Simulations - Introduction to Interface Design
Building Forio Web Simulations - Introduction to Interface DesignBuilding Forio Web Simulations - Introduction to Interface Design
Building Forio Web Simulations - Introduction to Interface Design
 
ASAE Tech: Data Data Everywhere
ASAE Tech: Data Data EverywhereASAE Tech: Data Data Everywhere
ASAE Tech: Data Data Everywhere
 
Get a Little Help with Your Help Desk Application
Get a Little Help with Your Help Desk ApplicationGet a Little Help with Your Help Desk Application
Get a Little Help with Your Help Desk Application
 
Essay Writing Service Reviews Top 10 Best Pap
Essay Writing Service Reviews Top 10 Best PapEssay Writing Service Reviews Top 10 Best Pap
Essay Writing Service Reviews Top 10 Best Pap
 
Trigger Emails BigD17
Trigger Emails BigD17Trigger Emails BigD17
Trigger Emails BigD17
 
Pratical Deep Dive into the Semantic Web - #smconnect
Pratical Deep Dive into the Semantic Web - #smconnectPratical Deep Dive into the Semantic Web - #smconnect
Pratical Deep Dive into the Semantic Web - #smconnect
 
Office 365 Productivity Tips "May Mediation"
Office 365 Productivity Tips "May Mediation"Office 365 Productivity Tips "May Mediation"
Office 365 Productivity Tips "May Mediation"
 
Ignite pitch
Ignite pitchIgnite pitch
Ignite pitch
 
Mis 1 Chapter
Mis 1 ChapterMis 1 Chapter
Mis 1 Chapter
 
Ruby on Rails Plugins - Rich Collins
Ruby on Rails Plugins - Rich CollinsRuby on Rails Plugins - Rich Collins
Ruby on Rails Plugins - Rich Collins
 
Cyber Threats and Data Privacy in a Digital World
Cyber Threats and Data Privacy in a Digital WorldCyber Threats and Data Privacy in a Digital World
Cyber Threats and Data Privacy in a Digital World
 
Improving Spreadsheet Test Practices
Improving Spreadsheet Test PracticesImproving Spreadsheet Test Practices
Improving Spreadsheet Test Practices
 
JDO 2019: Data Science for Developers - Matthew Renze
JDO 2019: Data Science for Developers -  Matthew RenzeJDO 2019: Data Science for Developers -  Matthew Renze
JDO 2019: Data Science for Developers - Matthew Renze
 
How to design with science and not destroy the magic
How to design with science and not destroy the magicHow to design with science and not destroy the magic
How to design with science and not destroy the magic
 
How to design with science: and not destroy the magic (Joe Leech)
How to design with science: and not destroy the magic (Joe Leech)How to design with science: and not destroy the magic (Joe Leech)
How to design with science: and not destroy the magic (Joe Leech)
 
Sydney Salesforce NFP user group july 2011
Sydney Salesforce NFP user group july 2011Sydney Salesforce NFP user group july 2011
Sydney Salesforce NFP user group july 2011
 
Becoming a Power User
Becoming a Power UserBecoming a Power User
Becoming a Power User
 
Data Data Everywhere: Drowning in a Sea of Analytics
Data Data Everywhere: Drowning in a Sea of AnalyticsData Data Everywhere: Drowning in a Sea of Analytics
Data Data Everywhere: Drowning in a Sea of Analytics
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 

The Mystery In The Models: The Basics of Adding a Model to your EE Add-on

Editor's Notes

  1. A model is class that represents a logical structure and associated database table. In other words, models manage data. EE has a number of models already there, like Channel, ChannelEntry, Member, Template, etc.
  2. - Create an Entry system/ee/EllisLab/ExpressionEngine/Controller/Publish/Publish.php - Read a Member system/ee/EllisLab/ExpressionEngine/Controller/Members/Members.php - Get a File with Relationship system/ee/EllisLab/ExpressionEngine/Controller/Files/Files.php
  3. Let’s help E720 change their site so people can upvote and downvote their content
  4. ### Create our Data and DB Tables - Models don't create your database tables by default, so we'll need to use the DBForge to create them. 1. Map our data first 2. Create schema in `upd` file
  5. ### Create our Data and DB Tables - Models don't create your database tables by default, so we'll need to use the DBForge to create them. 1. Map our data first 2. Create schema in `upd` file
  6. ### Initiate Our Model Models are registerd in your addon.setup.php file Add it to your add-on setup 1. `models` array 2. Lots of ways to extend this, we'll go through one way later
  7. ### Initiate Our Model Models are registerd in your addon.setup.php file Add it to your add-on setup 1. `models` array 2. Lots of ways to extend this, we'll go through one way later
  8. ### Scaffolding - Let's look at the basics of the model 1. Extend the EE Model class 2. Primary Key and Table Name are required 3. Protected Elements of the Model are your data points
  9. ### Let's Make it CRUDdy! 1. `votes` method: Reading the votes, Creating a new one 2. `cast_vote` method: Updating the votes
  10. ### Relationships - By nature of our Votes model, it's connected to a ChannelEntry. - Only problem is that we have not defined this relationship, so we would need multiple DB calls to get it. - Relationships relate entries 1. Define the relationship 2. Define the inverse (addon.setup and Vote model) 3. `top` method: Getting entries by the top voted ## What Else Can Models Do? - Events (i.e. update another model when your model is updated) - Validation (i.e. check to make sure data coming in is good and will save) - Metadata (i.e. setting variables re: whether model was updated) - Relationships with pivot tables (i.e. tagging entries, multiple entries can have multiple tags) - Collections (manage multiple items in your data)