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

PPT
Outlook Overview New Detroit Sept 2008
PPTX
Errors And Spreadsheets2
PPT
Lotusphere BoF - Working with the Lotus Connections API
PPT
Aen007 Kenigsberg 091807
PPTX
How Functional Programming Made Me A Better Developer
PPTX
Analyzing Cross-System User Modeling on the Social Web
PPTX
PhD Viva - Disambiguating Identity Web References using Social Data
PDF
Real World End to End machine Learning Pipeline
Outlook Overview New Detroit Sept 2008
Errors And Spreadsheets2
Lotusphere BoF - Working with the Lotus Connections API
Aen007 Kenigsberg 091807
How Functional Programming Made Me A Better Developer
Analyzing Cross-System User Modeling on the Social Web
PhD Viva - Disambiguating Identity Web References using Social Data
Real World End to End machine Learning Pipeline

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

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

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
Unlocking AI with Model Context Protocol (MCP)
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Mobile App Security Testing_ A Comprehensive Guide.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
sap open course for s4hana steps from ECC to s4
Building Integrated photovoltaic BIPV_UPV.pdf
MYSQL Presentation for SQL database connectivity
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
20250228 LYD VKU AI Blended-Learning.pptx
Ad

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

Editor's Notes

  • #5: 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.
  • #6: - 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
  • #10: Let’s help E720 change their site so people can upvote and downvote their content
  • #11: ### 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
  • #12: ### 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
  • #13: ### 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
  • #14: ### 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
  • #15: ### 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
  • #16: ### Let's Make it CRUDdy! 1. `votes` method: Reading the votes, Creating a new one 2. `cast_vote` method: Updating the votes
  • #17: ### 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)