Personal tools
You are here: Home > CS 342 Blog Entries > Folder with blog entries for William Barthel > MVC Design Pattern and a PHP Template Engine

MVC Design Pattern and a PHP Template Engine

by Barthel, William J last modified Apr 01, 2017 02:01 AM

This past week I had become more familiar with a design pattern that came up in a previous project that I worked on but was unable to recognize it at the time.  This is the model, view controller design pattern.  When I wasn't familiar with the purpose of this design pattern or how it worked everything was very confusing.  After discussing it in class and doing a quick lab focused around it I see how this technique can be very useful when organizing large scale projects.  The main idea of this design pattern is that code that is responsible for the GUI of the project is kept in the "view" portion of the code.  For the view to be displayed correctly depending on who is viewing the page it must talk to the controller.  I like to think of the view being a basic HTML page where the controller is the php that decides what data to display.  With this it's easy to think what the "model" portion of this design pattern represents.  Put simply, it's wherever the data is stored that is to be displayed on the view.  The view talks to the controller who then retrieves the correct data from model that goes on to be displayed on view.  Keeping all of these sections of code separate makes large projects much less hectic when trying to organize all of the code.

I began messing around with a PHP web page template engine this week as well.  The original project was featured in the book 500 Lines or Less, this project was built by Ned Batchelder.  The necessity for programs like these exist because of a few common web development issues.  "The web application developer has a problem to solve: how best to generate a large string containing a mix of static and dynamic data? To add to the problem, the static text is actually HTML markup that is authored by another member of the team, the front-end designer, who wants to be able to work with it in familiar ways."  This project modifies classic HTML pages into modified templates that when ran through a PHP script will generate the desired web page with both the desired static and dynamic portions of the page.  So far I have figured out how to use the project that Ned has created by running through his example of how his project works.  I am currently working on extending his project by allowing the HTML templates to allow custom tags and to be interpreted correctly by the template engine.

by Barthel, William J last modified Apr 01, 2017 02:01 AM
CS emphasis accredited by

ABET logo

Contact Us

Computer Science Department
UW Oshkosh
800 Algoma Blvd.
Oshkosh, WI 54901

Phone: (920) 424-2068
Fax: (920) 424-0045
Building: Halsey Science Hall

Rooms: 229 (general office), 221 (David Furcy, chair)

Email: Send mail to chair at