Several options are available to browse the archive. Pull down the menu to access the options. You can also stack and unstack thoughts, increase or decrease Text Size. It could improve your browsing experience, or not.
Browsing by Date (Oldest First)
4611 days ago
4615 days ago
4670 days ago
4677 days ago
4707 days ago
4722 days ago
4735 days ago
4740 days ago
4761 days ago
4761 days ago
Elegant Web Application, PART2
stack thought
4780 days ago

This is the 2nd of a multi-part series describing, in details, how
to create an elegant web application using php and mysql. I say ‘elegant’ because… yadda yadda) In this second part, I will explain how to design your web application so that the end result is flexible, robust and secure. Flexible because you’ll want to add features down the line and want your web app to be able to adapt to accomodate the new requirements. Robust because you want your web app to handle requests reliably. Secure because getting hacked isn’t fun.

Use cases
Use cases are useful but not necessary. If you already have a clear understanding of the problem you’re solving, you probably don’t need them. Here’s a good introduction to use cases and part two found at the excellent A List Apart. Use cases help a developer design an application.

Object Oriented (OO) design in PHP
OO design helps us achieve the 3 goals mentioned above (flexibility, security and robustness) but also, gives us code cleanliness, one of php’s weak points. For those new to OO design and programming, think of an object as being an entity within your program. This entity has distinct properties that makes it unique, and it has a distinct set of functions that makes it unique. Many scenarios can be represented using an OO approach.

A web app usually is a set of forms which allow a user to input information. After input, the web app processes/stores the information in a database, and allows other users to search and access portions/all of the information.

A good example of a web app is a survey form which is filled out by voluntary participants. As an example, we’re going to use an object oriented approach to represent this web app. In this case, we would have a survey object, a participant object and an administrator object. I usually also have my tried and tested common objects, which I use across projects. Since these common objects are “independant”, I can simply reuse the code across projects. The common objects I use are the xhtml object and a database object.

All the objects mentioned above have attributes and functions. For instance, the participant object probably has the following attributes: participant name, participant email, participant password, etc etc. In addition to attributes, objects also have a specific way of processing information (functions). These are the base functions I usually create for all objects: a Get function, a Save function, a SaveNew function, a Delete function.

Keep code, content and design as separate as possible.
This is one of the coolest part of designing an elegant web application. Creating an elegant web app means working doubly hard during the design phase of the application, rather than working hard later on. Once you’ve designed a great framework for your application, the code part of your application can remain untouched for a long time. Realistically though, clients will always push for more functionality, but because your code will be clean and separate from the content and design, you’ll be able to pull off the changes quite fast. The content part of your application will be in your database and will not get mixed up with how your application works. It’s extremly easy for the design part to get mixed up with the other 2. Separating out the design part of the website is a very cool thing to achieve but requires a lot of hard work. A good way of achieving this is through the use of a template engine. I’ve recently participated in a project where we created our own templating engine. I hope I’m able to give an example of how to achieve this in Part 3 or Part 4 (if there is one).

In Elegant Web Application PART3, I will recode an online classifieds website into OO architecture. There’ll also be less talk, and more downloadable code, a base project which you can use as a starting point to your own.