Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHPBelgium – Belgian PHP community PHPBelgium event 18-02-2009 MVC = Make Venerated Code? Patrick Allaert.

Similar presentations


Presentation on theme: "PHPBelgium – Belgian PHP community PHPBelgium event 18-02-2009 MVC = Make Venerated Code? Patrick Allaert."— Presentation transcript:

1 PHPBelgium – Belgian PHP community http://www.phpbelgium.be/ PHPBelgium event 18-02-2009 MVC = Make Venerated Code? Patrick Allaert

2 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) Tabellio ● Xoo°f (eXtensible Open Object Oriented Framework) Xoo°f ● KDESvn (Subversion frontend for KDE) KDESvn ● PHP (ext/ldap) PHP ● APM lead developer (Alternative PHP Monitor) APM ● Working @ AUSYAUSY ● PHPBelgium staff member PHPBelgium ● Blog: http://patrickallaert.blogspot.com/http://patrickallaert.blogspot.com/ ● Twitter: http://twitter.com/patrick_allaerthttp://twitter.com/patrick_allaert

3 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

4 PHPBelgium – Belgian PHP community http://www.phpbelgium.be/ Model-View-Controller (2) Controller Model View Requests DB (X)HTM L XML

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

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

7 PHPBelgium – Belgian PHP community http://www.phpbelgium.be/ Demo application /index.ph p /team.php?id=

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

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

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

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

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

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

14 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”

15 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 http://example.com/index.php?type=article&id=25&date=20020322 http://example.com/article/200203226 ● Enables better search engine indexing ● URIs are not supposed to change (Cool URIs don't 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?

16 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

17 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 ● ForceType application/x-httpd-php or: SetHandler application/x-httpd-php

18 PHPBelgium – Belgian PHP community http://www.phpbelgium.be/ Performance impact (index page) In requests/second, higher = better

19 PHPBelgium – Belgian PHP community http://www.phpbelgium.be/ Performance impact (team page) In requests/second, higher = better

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

21 PHPBelgium – Belgian PHP community http://www.phpbelgium.be/ Thanks :-) These slides will be available through: http://patrickallaert.blogspot.com/ http://patrickallaert.blogspot.com/

22 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.


Download ppt "PHPBelgium – Belgian PHP community PHPBelgium event 18-02-2009 MVC = Make Venerated Code? Patrick Allaert."

Similar presentations


Ads by Google