PHPJavascript

Web Development Guide – My Personal Library of Tutorials and Scripts

PHP Architectures or Design Patterns and MVC

August19

A brief explanation on PHP design pattern and MVC architecture in general.

PHP architecture or PHP Design Pattern is nothing but a concept of building PHP applications. It is a theoretical guidance for PHP developers in writing their code.It aims to reduce time consumption and increase performance of an application. These architectures or design pattern are not specific to PHP, applies to software engineering in general.

Design Patterns are simply defined solutions to common problems. Design patterns are not created by someone who sits in a room and decides to make a design pattern instead design patterns are proven solutions that are implemented over and over again through different projects. This re-use of the solution itself becomes a pattern. Don’t be intimidated by the fancy names given to design patterns, such as fa�ade, singleton or observer, they are exactly that just fancy names given to repeatable solutions.

Most PHP developers may first ask why use Design Patterns or why design in the first place. After all PHP is a scripting language usually used for simple web development, aren�t functions are good enough? Yes this is probably true if you work alone on small projects. But you will find Design and Design Patterns are beneficial in regards of:

  • Maintenance
  • Documentation
  • Readability
  • Easy when developing in large development teams
  • Developing Code to be used by other then yourself

Links
http://www.phpbuilder.com/columns/tim20001010.php3?page=1
http://www.devarticles.com/c/a/PHP/Introduction-to-Design-Patterns-Using-PHP/

MVC (Model View Controller) Architecture
Model-view-controller (MVC) is an architectural pattern used in software engineering. In complex computer applications that present a large amount of data to the user, a developer often wishes to separate data (model) and user interface (view) concerns, so that changes to the user interface will not affect data handling, and that the data can be reorganized without changing the user interface. The model-view-controller solves this problem by decoupling data access and business logic from data presentation and user interaction, by introducing an intermediate component: the controller.


It is common to split an application into separate layers: presentation (UI), domain logic, and data access. In MVC the presentation layer is further separated into view and controller. MVC encompasses more of the architecture of an application than is typical for a design pattern.MVC is often seen in web applications, where the view is the actual HTML page, and the controller is the code that gathers dynamic data and generates the content within the HTML. Finally the model is represented by the actual content, usually stored in a database or XML files.

Though MVC comes in different flavors, control flow generally works as follows:

  1. The user interacts with the user interface in some way (e.g., presses a button).
  2. A controller handles the input event from the user interface, often via a registered handler or callback.
  3. The controller accesses the model, possibly updating it in a way appropriate to the user’s action (e.g., controller updates user’s shopping cart).
  4. A view uses the model to generate an appropriate user interface (e.g., the view produces a screen listing the shopping cart contents). The view gets its own data from the model. The model has no direct knowledge of the view.
  5. The user interface waits for further user interactions, which begins the cycle anew.

Links

http://talks.php.net/show/zagreb2/1
http://en.wikipedia.org/wiki/Model-view-controller

PHP MVC Frameworks
Provides a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility. http://www.phpwact.org/php/mvc_frameworks
http://www.cakephp.org/

Books
http://www.amazon.com/PHP-Architects-Guide-Design-Patterns/dp/0973589825

posted under PHP

Email will not be published

Website example

Your Comment:

 

12,958 spam comments
blocked by
Akismet