Hello,
My question is about an organizational issue I am having with Object-oriented PHP (this script is going to be compatible with 4 and 5 until the later versions where I will fully-adopt PHP5 OOP). I think the issue is that I am still thinking too procedurally. I would appreciate some help.
I am creating a PHP poll/survey application that allows for multiple admins and templates, polls, surveys, blacklist, etc. I am currently working on the admin panel. I was advised that a good approach would be to create a class file for each page (e.g. "inc/class.page.admins.php"). So the url "index.php?sec=admins" would call that file, create an instance, and automatically call the function display() which would decide which functions to call.
The problem is that with these pages I am literally making a copy of the last class file and changing it around. This is because almost every section has four basic functions. You can add, edit, delete, and mass-delete items via the main page for the section which contains a table with all of the entries. So, for example, when you go to the "Manage Admins" page, you see a list of admin accounts, whether they are active or not, what permissions they have, etc. You can then add more accounts, edit, delete, or mass-delete (with checkboxes) existing accounts. Now, take the "Manage Blacklist" page, for example. The main page shows a list of what IP was blacklisted, when, etc. From there you can add more IPs, edit current ones, delete them, or mass-delete them. Very similar to the "Manage Admins" page. I ended up basically copying the Admins class and changing the names to create the page.
There has to be a more productive way to do this. I asked on IRC in a PHP channel and someone recommended to look at phpBB's code. I often do refer to it and actually did before I asked the question, but on the admin panel the only thing it shows in a table are forums. I have attached my index.php file and the inc/class.page.admins.php file in TXT format in a ZIP file. I would appreciate it if someone would give me some suggestions on a more productive way to go about solving my admin panel issue (re-using the same functions basically -- but I am not sure how I would create one common class for them) and any comments on the code/structure would be appreciated. I am a very meticulous person and I would really hate to avoid asking this question now and months later I figure out that my approach to OOP is all wrong (A couple things to note: a.) I am working my way to C++. I know PHP isn't the best OO language, but if I can pick up some idea of the concept of OOP while using PHP, that would be great. b.) I actually had a lengthy discussion with someone about how to structure this script with OOP, and that is how the whole ?sec=admins, etc thing came about. c.) I want to do this in OOP. I have been in countless debates on whether or not OOP is justified in my case(s) and, basically, it is a holy war ((like which text editor to use -- vi or emacs))).
Your feedback is greatly appreciated,
Technel