Re: Comments on my code Design...
| From: | Kevin Beckford | Date: | Wed, 21 Jun 2000 17:25:27 +0000 |
| Subject: | Re: Comments on my code Design... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-2515@lists.php.net to get a copy of this message | ||
> I'm new to PHP (2wks now) coming in from C++. My department has given me the
> specs to
> a website that I have till July 10 to do, *fun!*. So I was wanting your
> input on the
> design plan behind the modules, please expliot my 'newbie-ness' to PHP and
> flame the logic ;)
>
> Essentially the site is for student to come in and check their personal
> details, and the information for subjects (desc, class list, timetable (this
> is static)...).
>
> We have several types of users:
>
> students (check/change their details, link to subject pgs, ...)
> teachers (primarily just edit their class list)
> graduates (restricted browsing to certain pages that students can access)
> administrator (add/edit/delete above 3 user types)
>
> * The student information is stored as a MySQL database.
>
> Okay so this is all straight-forward, however I don't have the time to get
> this wrong, and therefore my logic can't be flawed from the beginning.
>
> Here's my plan:
>
> Classes -
> cStudent, cTeacher, cAlumni, cAdmin :parent: cUserBaseObj
> Classes for each user type, all derived from a common parent class.
Classes are great - however, be careful in using them in php. Search the
mailing list archives for 'classes' and see what OOP things are available to
you. I am no OOP master, but be sure that your design does not depend on
something like uh, operator overloading, which may not be available in PHP. No
data hiding and all that stuff.
> dbMySQL
> Database connectivity wrapper.
No need - PHP is optimized for this connectivity. I'd just make the calls and
use the results.
> cSession
> Session Management wrapper.
>
Before you write your own - check PHPLIB and phpclasses.upperdesign.com (You've
got a time deadline right?)
> Operation -
> - User attempts to access any page (in case of bookmarking).
> - Display Authenticate dialog box
> - Instantiate the Dbase Object, and check user
> - Return validity, and if valid what type of user (Student, Teacher...)
> - Check that they're allowed to access requested page, if not redirect
> them
> - Query the dbase as the page requires
> - Display requested page, filled with lovely database-derived content,
> *sweeet*
>
> My questions are -
> * Since the user object is required on every page they jump around to
> (they'll be
> moving between pages a fair bit), should I use Session stuff here, or
> default to
> global variables to maintain the data?
> This same question for the dbMySQL object.
>
Ok, HTTP is a stateless protocol. What you need here is a session object, that
will maintain state for each user. Build one or find one on the web. This
object will need to use some sort of container to store the session information
so that it can be retrieved from page to page.
For your mysql connection, however you decide to do it, use the pconnect
functions. That will make for a more efficient script.