Object-oriented programming applied to Web Sites
Date: 2000/06/29
Message-ID: <5VU65.1500$EA1.166637_at_news.total.net>#1/1
I began coding with the following structure:
---start of file
switch($action) {
case "": displayForm(); break; case "save": saveForm($formParams); break;
}
exit;
function displayForm() {
$objDB = new QueryTool($host, $user, $pass); $objDB->query("SELECT * FROM tablename"); while($row = $objDB->fetchRow()) { print $row['COL_NAME']; }
...
}
...
---end of file
Also, I created a class that "this" page should use to access to the database. Normally, we should use oracle_connect(), but with that class, I simply create a DB object, calling its connect, query, fetchRow, and close methods. This hides oracle, so we can change to whatever DB we want, in just a few hours, because we only need to swap the oracle class code to the new class.
Actually, I create two classes:
class QueryTool_oracle {
function connect(...
}
class QueryTool extends QueryTool_oracle {
// Nothing to add, just a class renaming trick
}
An other class is for controlling access with a username+password. Each file that needs authentification should include the file "verify_login". That file uses an object to login, verify that the user is logged, and logoff: class auth {
function login($username, $password); function verify(); function logout();
}
That class uses a cookie and a DB connection to remember who the user is. The cookie is a long random unique ID. The DB allows to to the translation cookie-->user_id.
This is how I program my websites for now, but I am wondering if there is not a nicer way. I want very modular and reusable code.
Any comments on my programming style? Any resources that discusses that kind of software?
Thanks for your help,
Nicolas Marchildon
Web Developper
Montréal, Québec, Canada
Received on Thu Jun 29 2000 - 00:00:00 CEST