Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy. This forum is not for asking programming related questions.
I'd like to get some input from some of the guys on this forum regarding how they would run the backend of a website like mine.
The main things i'm interested in are:
How would you interact with a database?
Would you write a database abstraction layer, hard-code everything for a particular database, or something else?
How would each page be generated?
Meaning how would the end result come to be? Would you include the page the user wants based on some variable in the url (i.e. index.php?page=xxx), use a templating engine, or something else?
OK first off.. I should just mention that maybe I'm too drunk to be answering posts
1. I'd usually write a class to exclusively handle the database stuff. Depending upon how I'm feeling I'll write something quite generic (which takes more time when you actually come to use it in terms of making calls to functions) or something that's pretty specific for the particular project your working on (convenient once coded).
2. I almost always use ?page=something and have recently started playing with mod_rewrite as Skara says. It's just so clean, tidy and efficient to include things into templates rather than have completely new pages for each URL.
3. Not sure... let me think while I drink
Generally on my sites I have an index which calls my navigation class.
I find this more beneficial than calling pages directly because I can now easily control things like custom errors, user's permissions, etc. I would also recommend using some sort of templating engine to seperate most of your logic from your html, of course this is much easier to maintain that entangling the two. If your looking for simple template creations, I would probably create your own templating class which isn't difficult at all. Not bashing Smarty but I find it to be overkill at times.
Generally I have a library class that I use over and over on every site. Things like such
1) Database Abstraction Layer
2) Navigation layer
3) User control layer
4) Templating layer
and so on. I'm sure that you've noticed certain patterns emerge when creating sites, atleast I know I have. 95% of the sites I do are CMS, so all of the mentioned can be re-used. Your own site is a perfect place to start developing these things.
Jcart, do you pull your navigation links from a database? I've been thinking about doing something like this so that I could add/delete pages from the web. Also, for your DBA do you use a factory class? It'd be nice if you could do something like:
Well i think programming is something personal, every programmer has it's own choices, for one i rather use 1 page as a tree for all the other pages. And as for a connection to a db, i hardcode every query and try to avoid putting the whole site into a database itself.. hehehe.. j/k..
I still have to start on OOP but sofar my sites are working, but there's always room for improvement.
But to answer your questions: I think it's a personal choice of how you code it and what you wanna do with a db.. But make sure you feel good about how you do it..