June 21, 2005

OOP is great, and some info about the site

Before you read this post, just understand that it’s more intended for myself than anyone else, and a lot of it won’t make sense. I’ll try and update later as to the changes, but the likely chance is that you won’t actually see any changes at all.

You’ll probably know that I built the code for this site myself. What you probably don’t know is that the backend of this website is rather complex, if I do say so myself. OOP (object-oriented programming) is used extensively throughout to make the backend really, really flexible. For instance, this backend could quite easily be taken out and put directly into another site without too much hassle at all.

The main idea is to use the database to provide content, and, to some extent, the layout for the site. My sites generally tend to sit in a simple fashion - have a toolbar on the left, right or perhaps both, with some floating divs over the place and a few other tweaks and fixes.

It would be much easier to draw a diagram right about now, but I’m too lazy for that so I won’t. However, this is how the whole thing basically works:

  • Instantiate a config object, and connect to the database using the various options.
  • Create a user object. This reads the cookies that are placed in your browser, and sees if you’re currently logged in.
  • Create a session object. This tracks your current session, as well as gather statistics and other menial things.
  • Create a layout object. This is where most of the work gets done. The page gets assembled and output with a variety of options.

Why is it good? Well, it allows for a great deal of abstraction between what I do in the pages themselves and the actual backend, making it easier to debug.

However, I want to take it a bit further; I basically want to ensure that if I wanted to take out the front-end and slap on a completely different site, I can do this. I originally designed the backend for a project that hasn’t yet been finished, and after moving it to realm, I bodged it a bit to make it work. So, I need to do a few things:

  • The layout object currently uses an object to specify various things about the page; i.e. the title, whether we want the toolbar to be displayed, etc. This is a nice little trick that I thought up; each sub-section can display different titles, have different outputs and all sorts of other stuff without messing around too much. Because everything’s buffered until the very last minute, it allows a lot of flexibility. I want to extend this idea - it can certainly be made nicer.
  • Again, the layout object needs to be seperated from specifics. I want to use template sets which are stored in the database, and then these can be parsed to allow for several style sets. It also allows for yet more abstraction.
  • The config options will vary depending on a variety of things. For instance, every site I code will have some sort of database connection, but not necessarily use my LaTeX plugin. I’d like to have some sort of inheritance going on there.
  • Standardize the CSS. This is important if I want to go on and make things better. However, I’m going to have to give this one some thought.
  • Get rid of the damn functions that are thrown about all over the place; all site-specific functions should be in a different file.
  • This is the important one: create a method for processing of form variables and the like. I think the best way of doing this is to modify the page object and provide a list of variables that the script expects. If one is missing or of an invalid type, then the layout object can deal with it in the appropriate manner. This way, I don’t have to do things like escaping strings before they go into the database, I can just shove them straight in without too many worries.

Also, some random facts for you: the backend by itself is over 1500 lines long - if you add the pages code to that (i.e. the stuff you guys actually see), it goes up to something like 3500 lines.

Anyway, I’m going to go off and get started, methinks. No time like the present, and all that.

6:33 pm | Posted in PHP/MySQL, Site Development

1 Comment »

  1. Griff
    21/6/2005 6:56 pm

    Gotta love OOP-PHP. I’m only just getting into it, and it’s made my code sooooo much nicer. If only I had the time to work on it more…. Damn these A-levels.

RSS feed for comments on this post.

Leave a comment