SlideShare ist ein Scribd-Unternehmen logo
1 von 22
PHPBelgium event 18-02-2009




   MVC = Make Venerated Code?


                                     Patrick Allaert


   PHPBelgium – Belgian PHP community
                    http://www.phpbelgium.be/
About Me
Started developping using PHP 3
Ten years of FOSS evangelism
Contribute to different FOSS:
   Tabellio (Open Source Collaboration for assemblies)
   Xoo°f (eXtensible Open Object Oriented Framework)
   KDESvn (Subversion frontend for KDE)
Lead developer:
   APM (Alternative PHP Monitor)
Working @ AUSY
Blog: http://patrickallaert.blogspot.com/


             PHPBelgium – Belgian PHP community
                                       http://www.phpbelgium.be/
Model-View-Controller (1)
“… is an architectural pattern used in software
 engineering. Successful use of the pattern
 isolates business logic from user interface
 considerations, resulting in an application
 where it is easier to modify either the visual
 appearance of the application or the underlying
 business rules without affecting the other.”
                                          Wikipedia


         PHPBelgium – Belgian PHP community
                          http://www.phpbelgium.be/
Model-View-Controller (2)


                                           Model
                                                          DB


Requests       Controller


                                                         (X)HTML
                                           View            XML




            PHPBelgium – Belgian PHP community
                             http://www.phpbelgium.be/
Design of some PHP applications




    PHPBelgium – Belgian PHP community
                     http://www.phpbelgium.be/
Managing this is sometimes...




           very difficult...
   PHPBelgium – Belgian PHP community
                    http://www.phpbelgium.be/
Demo application




/index.php                 /team.php?id=<TeamID>

PHPBelgium – Belgian PHP community
                 http://www.phpbelgium.be/
Spaghetti code




PHPBelgium – Belgian PHP community
                 http://www.phpbelgium.be/
Taking the Business Logic apart (1)




      PHPBelgium – Belgian PHP community
                       http://www.phpbelgium.be/
Taking the Business Logic apart (2)




      PHPBelgium – Belgian PHP community
                       http://www.phpbelgium.be/
Taking the Business Logic apart (3)




      PHPBelgium – Belgian PHP community
                       http://www.phpbelgium.be/
Evaluating the situation
Model is reusable         Views tightly linked to
Changes to the              the model
 business logic does      Views impacted if the
 not require inspecting     API of the model
 all files                  change
                          Calls to the model may
                            be difficult to find:
                            spread everywhere in
                            views

        PHPBelgium – Belgian PHP community
                          http://www.phpbelgium.be/
On the path to MVC (1)




PHPBelgium – Belgian PHP community
                 http://www.phpbelgium.be/
On the path to MVC (2)
Directory views to be added in the include_path
View parameters are passed using global
  variables
  Hint: $variableName may also be written:
  $GLOBALS['variableName']
  The latest form may be used to differentiate
  variables defined by the controller file from the
  local view variables
“htdocs” could be renamed “controllers”

         PHPBelgium – Belgian PHP community
                           http://www.phpbelgium.be/
Howto: Clean URL
Clean URL: Transforming
   http://example.com/index.php?type=article&id=25&date=20020322into:
   http://example.com/article/200203226
Enables better search engine indexing
URIs are not supposed to change (Cool URIs don't change)
Doesn't expose the server-side language
Most MVC Frameworks provide clean URL mechanism, how to
  setup one with our structure?




             PHPBelgium – Belgian PHP community
                                      http://www.phpbelgium.be/
Clean URL: method #1
Using Apache's mod_rewrite:
 RewriteEngine On
 RewriteRule ^/team/([0-9]*)$ /team.php?id=$1 [L]

Ability to transform URLs on the fly and mapping
 part of the URL directly to a $_GET variable




         PHPBelgium – Belgian PHP community
                             http://www.phpbelgium.be/
Clean URL: method #2
Dropping the “.php” extension and forcing the
 mime-type/handler used in the Apache
 configuration
<FilesMatch "^(index|team)$">
      ForceType application/x-httpd-php
  </FilesMatch>
 or:
 <FilesMatch "^(index|team)$">
     SetHandler application/x-httpd-php
 </FilesMatch>


        PHPBelgium – Belgian PHP community
                         http://www.phpbelgium.be/
Performance impact (index page)

 Concurrency           1                           15
 “spaghetti”         1483.15                     2798.23
 Model-View          1353.17                     2388.61
 MVC                 1339.72                     2364.66
 Clean URL #1        1320.61                     2303.99
 Clean URL #2        1412.43                     2468.83
 Zend Framework       164.11                     280.22
                               In requests/second, higher = better




         PHPBelgium – Belgian PHP community
                               http://www.phpbelgium.be/
Performance impact (team page)

 Concurrency           1                           15
 “spaghetti”         1372.66                     2428.79
 Model-View          1243.78                     2142.79
 MVC                 1235.48                     2364.66
 Clean URL #1        1232.39                     2090.51
 Clean URL #2        1192.78                     2040.44
 Zend Framework      158.77                      264.65
                               In requests/second, higher = better




         PHPBelgium – Belgian PHP community
                               http://www.phpbelgium.be/
Questions ?




PHPBelgium – Belgian PHP community
                 http://www.phpbelgium.be/
Thanks :-)




These slides will be available through:
        http://patrickallaert.blogspot.com/




   PHPBelgium – Belgian PHP community
                          http://www.phpbelgium.be/
License
This presentation material is published under the Creative Commons Attribution-Share Alike 3.0 Unported license.
You are free:
to Share — to copy, distribute and transmit the work
to Remix — to adapt the work
Under the following conditions:
Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that
  suggests that they endorse you or your use of the work).
Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the
  same, similar or a compatible license.
With the understanding that:
Waiver — Any of the above conditions can be waived if you get permission from the copyright holder.
Other Rights — In no way are any of the following rights affected by the license:
  Your fair dealing or fair use rights;
  The author's moral rights;
  Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy
    rights.
Notice — For any reuse or distribution, you must make clear to others the license terms of this work.




                         PHPBelgium – Belgian PHP community
                                                             http://www.phpbelgium.be/

Weitere ähnliche Inhalte

Andere mochten auch

La métrique, ce n'est pas que pour le devops
La métrique, ce n'est pas que pour le devopsLa métrique, ce n'est pas que pour le devops
La métrique, ce n'est pas que pour le devopsPatrick Allaert
 
Maitriser les structures de données PHP 102 - Forum Paris 2012
Maitriser les structures de données PHP 102 - Forum Paris 2012Maitriser les structures de données PHP 102 - Forum Paris 2012
Maitriser les structures de données PHP 102 - Forum Paris 2012Patrick Allaert
 
Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)Patrick Allaert
 
Mastering PHP Data Structure 102 - phpDay 2012 Verona
Mastering PHP Data Structure 102 - phpDay 2012 VeronaMastering PHP Data Structure 102 - phpDay 2012 Verona
Mastering PHP Data Structure 102 - phpDay 2012 VeronaPatrick Allaert
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaPatrick Allaert
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPatrick Allaert
 

Andere mochten auch (6)

La métrique, ce n'est pas que pour le devops
La métrique, ce n'est pas que pour le devopsLa métrique, ce n'est pas que pour le devops
La métrique, ce n'est pas que pour le devops
 
Maitriser les structures de données PHP 102 - Forum Paris 2012
Maitriser les structures de données PHP 102 - Forum Paris 2012Maitriser les structures de données PHP 102 - Forum Paris 2012
Maitriser les structures de données PHP 102 - Forum Paris 2012
 
Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)
 
Mastering PHP Data Structure 102 - phpDay 2012 Verona
Mastering PHP Data Structure 102 - phpDay 2012 VeronaMastering PHP Data Structure 102 - phpDay 2012 Verona
Mastering PHP Data Structure 102 - phpDay 2012 Verona
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 Verona
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
 

Ähnlich wie MVC = Make Venerated Code?

Rapid Development With CakePHP
Rapid Development With CakePHPRapid Development With CakePHP
Rapid Development With CakePHPEdureka!
 
Vue micro frontend implementation patterns
Vue micro frontend implementation patternsVue micro frontend implementation patterns
Vue micro frontend implementation patternsAlbert Brand
 
Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_companyGanesh Kulkarni
 
CodeIgniter Basics - Tutorial for Beginners
CodeIgniter Basics - Tutorial for Beginners CodeIgniter Basics - Tutorial for Beginners
CodeIgniter Basics - Tutorial for Beginners Isuru Thilakarathne
 
PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterPHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterKHALID C
 
Php through the eyes of a hoster: PHPNW10
Php through the eyes of a hoster: PHPNW10Php through the eyes of a hoster: PHPNW10
Php through the eyes of a hoster: PHPNW10Combell NV
 
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...Gaetano Giunta
 
Php Frameworks
Php FrameworksPhp Frameworks
Php FrameworksRyan Davis
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerJackson F. de A. Mafra
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!Muhammad Ghazali
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend FrameworkPhil Brown
 
Workshop: Refactoring Legacy PHP: The Complete Guide
Workshop: Refactoring Legacy PHP: The Complete Guide Workshop: Refactoring Legacy PHP: The Complete Guide
Workshop: Refactoring Legacy PHP: The Complete Guide Junade Ali
 
Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...
Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...
Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...JPLoft Solutions
 

Ähnlich wie MVC = Make Venerated Code? (20)

Rapid Development With CakePHP
Rapid Development With CakePHPRapid Development With CakePHP
Rapid Development With CakePHP
 
Cakephp manual-11
Cakephp manual-11Cakephp manual-11
Cakephp manual-11
 
Vue micro frontend implementation patterns
Vue micro frontend implementation patternsVue micro frontend implementation patterns
Vue micro frontend implementation patterns
 
Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
 
CodeIgniter Basics - Tutorial for Beginners
CodeIgniter Basics - Tutorial for Beginners CodeIgniter Basics - Tutorial for Beginners
CodeIgniter Basics - Tutorial for Beginners
 
PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterPHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniter
 
Php through the eyes of a hoster: PHPNW10
Php through the eyes of a hoster: PHPNW10Php through the eyes of a hoster: PHPNW10
Php through the eyes of a hoster: PHPNW10
 
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
 
Magento
MagentoMagento
Magento
 
Php Frameworks
Php FrameworksPhp Frameworks
Php Frameworks
 
Php myadmin
Php myadminPhp myadmin
Php myadmin
 
Php Framework
Php FrameworkPhp Framework
Php Framework
 
Php framework
Php frameworkPhp framework
Php framework
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!
 
Introduction To CodeIgniter
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniter
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend Framework
 
Workshop: Refactoring Legacy PHP: The Complete Guide
Workshop: Refactoring Legacy PHP: The Complete Guide Workshop: Refactoring Legacy PHP: The Complete Guide
Workshop: Refactoring Legacy PHP: The Complete Guide
 
Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...
Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...
Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...
 

Kürzlich hochgeladen

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 

Kürzlich hochgeladen (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

MVC = Make Venerated Code?

  • 1. PHPBelgium event 18-02-2009 MVC = Make Venerated Code? Patrick Allaert PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 2. About Me Started developping using PHP 3 Ten years of FOSS evangelism Contribute to different FOSS: Tabellio (Open Source Collaboration for assemblies) Xoo°f (eXtensible Open Object Oriented Framework) KDESvn (Subversion frontend for KDE) Lead developer: APM (Alternative PHP Monitor) Working @ AUSY Blog: http://patrickallaert.blogspot.com/ PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 3. Model-View-Controller (1) “… is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other.” Wikipedia PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 4. Model-View-Controller (2) Model DB Requests Controller (X)HTML View XML PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 5. Design of some PHP applications PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 6. Managing this is sometimes... very difficult... PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 7. Demo application /index.php /team.php?id=<TeamID> PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 8. Spaghetti code PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 9. Taking the Business Logic apart (1) PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 10. Taking the Business Logic apart (2) PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 11. Taking the Business Logic apart (3) PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 12. Evaluating the situation Model is reusable Views tightly linked to Changes to the the model business logic does Views impacted if the not require inspecting API of the model all files change Calls to the model may be difficult to find: spread everywhere in views PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 13. On the path to MVC (1) PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 14. On the path to MVC (2) Directory views to be added in the include_path View parameters are passed using global variables Hint: $variableName may also be written: $GLOBALS['variableName'] The latest form may be used to differentiate variables defined by the controller file from the local view variables “htdocs” could be renamed “controllers” PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 15. Howto: Clean URL Clean URL: Transforming http://example.com/index.php?type=article&id=25&date=20020322into: http://example.com/article/200203226 Enables better search engine indexing URIs are not supposed to change (Cool URIs don't change) Doesn't expose the server-side language Most MVC Frameworks provide clean URL mechanism, how to setup one with our structure? PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 16. Clean URL: method #1 Using Apache's mod_rewrite: RewriteEngine On RewriteRule ^/team/([0-9]*)$ /team.php?id=$1 [L] Ability to transform URLs on the fly and mapping part of the URL directly to a $_GET variable PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 17. Clean URL: method #2 Dropping the “.php” extension and forcing the mime-type/handler used in the Apache configuration <FilesMatch "^(index|team)$"> ForceType application/x-httpd-php </FilesMatch> or: <FilesMatch "^(index|team)$"> SetHandler application/x-httpd-php </FilesMatch> PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 18. Performance impact (index page) Concurrency 1 15 “spaghetti” 1483.15 2798.23 Model-View 1353.17 2388.61 MVC 1339.72 2364.66 Clean URL #1 1320.61 2303.99 Clean URL #2 1412.43 2468.83 Zend Framework 164.11 280.22 In requests/second, higher = better PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 19. Performance impact (team page) Concurrency 1 15 “spaghetti” 1372.66 2428.79 Model-View 1243.78 2142.79 MVC 1235.48 2364.66 Clean URL #1 1232.39 2090.51 Clean URL #2 1192.78 2040.44 Zend Framework 158.77 264.65 In requests/second, higher = better PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 20. Questions ? PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 21. Thanks :-) These slides will be available through: http://patrickallaert.blogspot.com/ PHPBelgium – Belgian PHP community http://www.phpbelgium.be/
  • 22. License This presentation material is published under the Creative Commons Attribution-Share Alike 3.0 Unported license. You are free: to Share — to copy, distribute and transmit the work to Remix — to adapt the work Under the following conditions: Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license. With the understanding that: Waiver — Any of the above conditions can be waived if you get permission from the copyright holder. Other Rights — In no way are any of the following rights affected by the license: Your fair dealing or fair use rights; The author's moral rights; Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights. Notice — For any reuse or distribution, you must make clear to others the license terms of this work. PHPBelgium – Belgian PHP community http://www.phpbelgium.be/