Hudzilla.org - the homepage of Paul Hudson
Contents > Practical PHP > Creating a messageboard Wish List | Report Bug | About Me ]

22.3.6     Making an object-oriented messageboard

This is NOT the latest copy of this book; click here for the latest version.

Owing to the vast amount of functionality you can cram into something so seemingly simple as a messageboard, it's a prime candidate for object-orientated programming. For example, rather than writing lots of complex code to print out the message index, wouldn't it be much easier to write this:

$mb = new messageboard("general");
$mb->setStyle($mb::StyleThreaded);
$mb->setLimit(50);
$mb->print();

Naturally you need to write all the back-end code to do those things, but you'll find it actually saves you a huge amount of work to program APIs to access your data rather than wading in with custom SQL each time. For example, we could print a summary of new posts in a given messageboard with code like this:

$mb = new messageboard("general");
$mb->setStyle($mb::StyleGuestbook);
$mb->setLimit(5);
$mb->print();

As you can see, we've got a huge amount of code re-use here, which maximises productivity while minimising errors. All the code above was for a non-OOP messageboard, but all you need to do is find the common processes and abstract them to functions in order to convert it - it should take you maybe two hours if you give it a try, but the time savings for maintaining that code make the effort well worth it.





<< 22.3.5 Messageboard v2   22.4 Creating thumbnails >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
A PHP User - 29 Aug 2008

Boo!

A PHP User - 29 Aug 2008

test

A PHP User - 29 Aug 2008

test



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is one plus three?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow