SlideShare ist ein Scribd-Unternehmen logo
1 von 43
What’s really under
     the hood?
How I learned to stop worrying and love Magento
Who am I?
• Alan Storm
• http://alanstorm.com
• Got involved in The Internet/Web 1995
• Work in the Agency/Startup Space
• 10 years php experience
• The thing you can never say ...
Not a Computer Scientist
 • Many developers and programmers aren’t
 • You don't need to be a computer scientist
   to work with Magento
 • Magento is similar to PHP Frameworks
   (Cake, CodeIgniter, Kohana), just deeper
 • Magento and Kohana, side by side
 • But first
How We Got Here
 A Brief History of Web Development
HTML Page
HTML Page

• Very radical shift
• No programming needed, just markup
• No proprietary file format, just ASCII text
• Limited interactivity, SSIs
“Scripting” vs.
  “Real Programming"
• HTML included markup for form elements
• Stealth runtime, with client/server approach
• “Real Programmers” could do everything in
  C, C++, Java, lisp
• “Scripters” could piggy back on the web
  server for HTTP and produce HTML
Perl/CGI
• Perl was once the new hotness
• Excelled as string processing, and Web
  applications are strings over HTTP
• CPAN meant a shared code library
• Non-complied meant distributed programs
  were shared in the open
Perl/CGI

• CGI was slow, and FastCGI too new
• Perl didn't scale way before ruby didn't
• CPAN’s good but no standard library for
  the growing shared hosting ecosystem
PHP3/PHP4
• Looks like Perl! Sort of.
• Build important features directly into
  language, distributed by default
• Could import C code as extensions
• The build-up/tear-down approach of
  mod_php ideal for shared hosts
PHP Page
Rise of PHP Systems
• Created to combat PHP Applications
  becoming too complex/messy
• Shopping Cart Applications
• CMS systems (Drupal, Mambo, Joomla)
• Programming Frameworks, many inspired
  by Ruby on Rails (CakePHP, Code Igniter,
  Symfony)
Magento is the Next
  Evolutionary Step
• Is a shopping cart application
• Uses a module based approach to load new
  code into the system, similar to Drupal
• Implements a configuration based MVC
• Most PHP Frameworks are convention
  based, Magento is configuration based
Controllers and
           Routing
A Web MVC Router transforms the request URL into a
 controller class name and decides which method on
           that controller is the entry point
Kohana Routing

• Routing handled by Router_Core::setup
• URI: /controllerName/actionName
• URI: /welcome/index
• Welcome_Controller::index();
• File: /application/controllers/welcome.php
Magento Routing

• URI: /frontName/controllerName/actionName
• URI: /catalogsearch/result/index
• No Standard Router!
Magento Routing
• Magento Searches Global Config for
  routers
 • web/routers
• Default system ships with two Routers
 •   Mage_Core_Controller_Varien_Router_Admin

 •   Mage_Core_Controller_Varien_Router_Standard

• Configured in Mage_Core
Magento Routing

• The match method is called on each router
• The match method is responsible for
 • Creating a Controller class
 • Creating an Action method
 • Calling the Action method
Magento Routing
• URI: /frontName/controllerName/actionName
• URI: /catalogsearch/result/index
• Default routers will
 • Gather any module with a configured
   <frontName>catalogsearch</frontName>

 • Check modules controllers folder for a
   Packagename_Modulename_ControllerName
    Mage_CatalogSearch_ResultController
Magento Routing
• /frontName/controllerName/actionName
• /catalogsearch/result/index
• If a Controller is found, Router checks if for
  an action.
  •   Mage_CatalogSearch_ResultController::indexAction

• If action is found, it’s called, and the module
  search and match search stops.
Magento Routing
• Most of the time in a fresh install
 • /catalogsearch/result/index
 • translates to
   • Module: Mage_CatalogSearch
   • Controller: ResultController
   • Action: indexAction
Magento Routing
• Possible to Add Additional Routers through
  event system
 •   controller_front_init_routers

• See
 •   Mage_Cms_Controller_Router::initControllerRouters

 •   Sets up Mage_Cms_Controller_Router with different
     match rules
Front Controller

                            Mage_Core_Controller_Varien_Router_Admin

 Looks at Global Config
and Instantiates Routers

                           Mage_Core_Controller_Varien_Router_Standard

  Goes through each
Router and calls match()                      match()
  until a controller is
      dispatched
                                      Builds a list of Moules
                                     with matching frontName


                                     Check each module until
                                     it finds a valid controller/
                                             action pair
Models
Getting out of the SQL Writing Business
Kohana Models

• Extend from Base ORM class
• Mostly follows Active Record Pattern
 • Create, Read, Update, Delete
• Simple Class Instantiation
Magento Models
• Most Complex Models implement an Entity
  Attribute Value store
• Simpler “basic” models offers Active
  Record like functionality
• Implement a Mapper pattern, making Model
  independant of data store
• Client Programmer doesn’t need to know
  these details to use.
Magento Models
• Magento Replaces direction instantiation
     with a indirect static method call
 •    $user = new User();

 •    $customer = Mage::getModel(‘cusotmer/customer’);


• Every model has a Collection object which is
     used when fetching for multiple models.
     Kohana and other frameworks, return PHP
     arrays()
Views
It all comes back to HTML
Kohana View
                           Controller


Contrller Interacts with                Controller Picks specific
Model based on request                  variables to send to view




     Model                                    View
Kohana View

• Traditional PHP MVC View Pattern
• Views are PHP mixed with HTML
• Often called “Dumb View”, since the View
  doesn’t know anything about the Application
Magento View
                             Controller


Contrller Interacts with                              Controller Tells
Model based on request                                View to Kick Off




     Model                                               View
                           View Reads Data Directly
                              from Model Objects
Controller


Contrller Interacts with                              Controller Tells
Model based on request                                View to Kick Off




     Model                                               View
                           View Reads Data Directly
                              from Model Objects
Controller


Contrller Interacts with                Controller Tells
Model based on request                  View to Kick Off


                                                Layout is a nested collection
                                               of recursively rendering blocks


     Model                               Layout

                                          Root Block


                                                   Block

                                                   Block
     Blocks Read
     Data Directly
      from Model                                   Block
        Objects
                                                           Block

                                                   Block
Magento Block
• The simplest block is just a PHP class with
  a toHtml(), which returns a string
• Many Blocks render via a phtml template
• From within a phtml template, $this is a
  reference to the containing Block
• The phtml templates contain HTML and
  PHP code for rendering logic
• Block methods communicate with Models
Block Class




Template for Block
                     Templates may be set
                     programmatically or via
                     the Layout XML files
What’s really under
     the hood?
How I learned to stop worrying and love Magento

Weitere ähnliche Inhalte

Andere mochten auch

2017 Social Media & Content Marketing Predictions from 70 Marketing Leaders
2017 Social Media & Content Marketing Predictions from 70 Marketing Leaders 2017 Social Media & Content Marketing Predictions from 70 Marketing Leaders
2017 Social Media & Content Marketing Predictions from 70 Marketing Leaders Bryan Kramer
 
Omnichannel Customer Experience
Omnichannel Customer ExperienceOmnichannel Customer Experience
Omnichannel Customer ExperienceDivante
 
E-commerce Trends from 2015 to 2016 by Divante
E-commerce Trends from 2015 to 2016 by DivanteE-commerce Trends from 2015 to 2016 by Divante
E-commerce Trends from 2015 to 2016 by DivanteDivante
 
Digital marketing Trends 2017
Digital marketing Trends 2017Digital marketing Trends 2017
Digital marketing Trends 2017Infocrest
 
SEO for Ecommerce: A Comprehensive Guide
SEO for Ecommerce: A Comprehensive GuideSEO for Ecommerce: A Comprehensive Guide
SEO for Ecommerce: A Comprehensive GuideAdam Audette
 
Digital Marketing Trends 2017
Digital Marketing Trends 2017Digital Marketing Trends 2017
Digital Marketing Trends 2017Webrepublic
 
Social Media Trends 2017
Social Media Trends 2017Social Media Trends 2017
Social Media Trends 2017Chris Baker
 
Digital Trends in 2017: Making Business Impact in a Changing World
Digital Trends in 2017: Making Business Impact in a Changing WorldDigital Trends in 2017: Making Business Impact in a Changing World
Digital Trends in 2017: Making Business Impact in a Changing WorldEdelman
 
Finding Your Way: Understanding Magento Code
Finding Your Way: Understanding Magento CodeFinding Your Way: Understanding Magento Code
Finding Your Way: Understanding Magento CodeBen Marks
 
Magento 2 product import export
Magento 2 product import exportMagento 2 product import export
Magento 2 product import exportBenno Lippert
 
How to Install Magento on WAMP Server
How to Install Magento on WAMP ServerHow to Install Magento on WAMP Server
How to Install Magento on WAMP ServerAPPSeCONNECT
 
Shipping Table Rates for Magento 2 by Amasty | User Guide
Shipping Table Rates for Magento 2 by Amasty | User GuideShipping Table Rates for Magento 2 by Amasty | User Guide
Shipping Table Rates for Magento 2 by Amasty | User GuideAmasty
 

Andere mochten auch (12)

2017 Social Media & Content Marketing Predictions from 70 Marketing Leaders
2017 Social Media & Content Marketing Predictions from 70 Marketing Leaders 2017 Social Media & Content Marketing Predictions from 70 Marketing Leaders
2017 Social Media & Content Marketing Predictions from 70 Marketing Leaders
 
Omnichannel Customer Experience
Omnichannel Customer ExperienceOmnichannel Customer Experience
Omnichannel Customer Experience
 
E-commerce Trends from 2015 to 2016 by Divante
E-commerce Trends from 2015 to 2016 by DivanteE-commerce Trends from 2015 to 2016 by Divante
E-commerce Trends from 2015 to 2016 by Divante
 
Digital marketing Trends 2017
Digital marketing Trends 2017Digital marketing Trends 2017
Digital marketing Trends 2017
 
SEO for Ecommerce: A Comprehensive Guide
SEO for Ecommerce: A Comprehensive GuideSEO for Ecommerce: A Comprehensive Guide
SEO for Ecommerce: A Comprehensive Guide
 
Digital Marketing Trends 2017
Digital Marketing Trends 2017Digital Marketing Trends 2017
Digital Marketing Trends 2017
 
Social Media Trends 2017
Social Media Trends 2017Social Media Trends 2017
Social Media Trends 2017
 
Digital Trends in 2017: Making Business Impact in a Changing World
Digital Trends in 2017: Making Business Impact in a Changing WorldDigital Trends in 2017: Making Business Impact in a Changing World
Digital Trends in 2017: Making Business Impact in a Changing World
 
Finding Your Way: Understanding Magento Code
Finding Your Way: Understanding Magento CodeFinding Your Way: Understanding Magento Code
Finding Your Way: Understanding Magento Code
 
Magento 2 product import export
Magento 2 product import exportMagento 2 product import export
Magento 2 product import export
 
How to Install Magento on WAMP Server
How to Install Magento on WAMP ServerHow to Install Magento on WAMP Server
How to Install Magento on WAMP Server
 
Shipping Table Rates for Magento 2 by Amasty | User Guide
Shipping Table Rates for Magento 2 by Amasty | User GuideShipping Table Rates for Magento 2 by Amasty | User Guide
Shipping Table Rates for Magento 2 by Amasty | User Guide
 

Kürzlich hochgeladen

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Kürzlich hochgeladen (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

How I Learned to Stop Worrying and Love Magento

  • 1. What’s really under the hood? How I learned to stop worrying and love Magento
  • 2. Who am I? • Alan Storm • http://alanstorm.com • Got involved in The Internet/Web 1995 • Work in the Agency/Startup Space • 10 years php experience • The thing you can never say ...
  • 3. Not a Computer Scientist • Many developers and programmers aren’t • You don't need to be a computer scientist to work with Magento • Magento is similar to PHP Frameworks (Cake, CodeIgniter, Kohana), just deeper • Magento and Kohana, side by side • But first
  • 4. How We Got Here A Brief History of Web Development
  • 6. HTML Page • Very radical shift • No programming needed, just markup • No proprietary file format, just ASCII text • Limited interactivity, SSIs
  • 7. “Scripting” vs. “Real Programming" • HTML included markup for form elements • Stealth runtime, with client/server approach • “Real Programmers” could do everything in C, C++, Java, lisp • “Scripters” could piggy back on the web server for HTTP and produce HTML
  • 8. Perl/CGI • Perl was once the new hotness • Excelled as string processing, and Web applications are strings over HTTP • CPAN meant a shared code library • Non-complied meant distributed programs were shared in the open
  • 9. Perl/CGI • CGI was slow, and FastCGI too new • Perl didn't scale way before ruby didn't • CPAN’s good but no standard library for the growing shared hosting ecosystem
  • 10. PHP3/PHP4 • Looks like Perl! Sort of. • Build important features directly into language, distributed by default • Could import C code as extensions • The build-up/tear-down approach of mod_php ideal for shared hosts
  • 12.
  • 13.
  • 14. Rise of PHP Systems • Created to combat PHP Applications becoming too complex/messy • Shopping Cart Applications • CMS systems (Drupal, Mambo, Joomla) • Programming Frameworks, many inspired by Ruby on Rails (CakePHP, Code Igniter, Symfony)
  • 15. Magento is the Next Evolutionary Step • Is a shopping cart application • Uses a module based approach to load new code into the system, similar to Drupal • Implements a configuration based MVC • Most PHP Frameworks are convention based, Magento is configuration based
  • 16. Controllers and Routing A Web MVC Router transforms the request URL into a controller class name and decides which method on that controller is the entry point
  • 17. Kohana Routing • Routing handled by Router_Core::setup • URI: /controllerName/actionName • URI: /welcome/index • Welcome_Controller::index(); • File: /application/controllers/welcome.php
  • 18. Magento Routing • URI: /frontName/controllerName/actionName • URI: /catalogsearch/result/index • No Standard Router!
  • 19. Magento Routing • Magento Searches Global Config for routers • web/routers • Default system ships with two Routers • Mage_Core_Controller_Varien_Router_Admin • Mage_Core_Controller_Varien_Router_Standard • Configured in Mage_Core
  • 20.
  • 21. Magento Routing • The match method is called on each router • The match method is responsible for • Creating a Controller class • Creating an Action method • Calling the Action method
  • 22. Magento Routing • URI: /frontName/controllerName/actionName • URI: /catalogsearch/result/index • Default routers will • Gather any module with a configured <frontName>catalogsearch</frontName> • Check modules controllers folder for a Packagename_Modulename_ControllerName Mage_CatalogSearch_ResultController
  • 23. Magento Routing • /frontName/controllerName/actionName • /catalogsearch/result/index • If a Controller is found, Router checks if for an action. • Mage_CatalogSearch_ResultController::indexAction • If action is found, it’s called, and the module search and match search stops.
  • 24. Magento Routing • Most of the time in a fresh install • /catalogsearch/result/index • translates to • Module: Mage_CatalogSearch • Controller: ResultController • Action: indexAction
  • 25.
  • 26. Magento Routing • Possible to Add Additional Routers through event system • controller_front_init_routers • See • Mage_Cms_Controller_Router::initControllerRouters • Sets up Mage_Cms_Controller_Router with different match rules
  • 27. Front Controller Mage_Core_Controller_Varien_Router_Admin Looks at Global Config and Instantiates Routers Mage_Core_Controller_Varien_Router_Standard Goes through each Router and calls match() match() until a controller is dispatched Builds a list of Moules with matching frontName Check each module until it finds a valid controller/ action pair
  • 28. Models Getting out of the SQL Writing Business
  • 29. Kohana Models • Extend from Base ORM class • Mostly follows Active Record Pattern • Create, Read, Update, Delete • Simple Class Instantiation
  • 30.
  • 31. Magento Models • Most Complex Models implement an Entity Attribute Value store • Simpler “basic” models offers Active Record like functionality • Implement a Mapper pattern, making Model independant of data store • Client Programmer doesn’t need to know these details to use.
  • 32.
  • 33.
  • 34. Magento Models • Magento Replaces direction instantiation with a indirect static method call • $user = new User(); • $customer = Mage::getModel(‘cusotmer/customer’); • Every model has a Collection object which is used when fetching for multiple models. Kohana and other frameworks, return PHP arrays()
  • 35. Views It all comes back to HTML
  • 36. Kohana View Controller Contrller Interacts with Controller Picks specific Model based on request variables to send to view Model View
  • 37. Kohana View • Traditional PHP MVC View Pattern • Views are PHP mixed with HTML • Often called “Dumb View”, since the View doesn’t know anything about the Application
  • 38. Magento View Controller Contrller Interacts with Controller Tells Model based on request View to Kick Off Model View View Reads Data Directly from Model Objects
  • 39. Controller Contrller Interacts with Controller Tells Model based on request View to Kick Off Model View View Reads Data Directly from Model Objects
  • 40. Controller Contrller Interacts with Controller Tells Model based on request View to Kick Off Layout is a nested collection of recursively rendering blocks Model Layout Root Block Block Block Blocks Read Data Directly from Model Block Objects Block Block
  • 41. Magento Block • The simplest block is just a PHP class with a toHtml(), which returns a string • Many Blocks render via a phtml template • From within a phtml template, $this is a reference to the containing Block • The phtml templates contain HTML and PHP code for rendering logic • Block methods communicate with Models
  • 42. Block Class Template for Block Templates may be set programmatically or via the Layout XML files
  • 43. What’s really under the hood? How I learned to stop worrying and love Magento

Hinweis der Redaktion