The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Ive only heard of templates being stored in a database once. Wayne Luke says vbulletin stores templates in the database for a couple of good reasons. That sort of thing is not for your run of the mill application however.

In another post SweatJe had a go at you because of your posts and I couldn't understand as to why. Now I do

It appears that you are limiting your application in ways that you (yet) do not understand simple because you have this idea that the database templating method is your 'only choice' is what I'm getting from your various posts.

Lastcraft has explained why your choice is bad but what happens for example when you roll out your application and someone requests Postgres or Oracle? Er, exactly... You'd be up the clyde without a paddle (goggle the phase if your lost in the translation).

Very rare occasion you'd use a database for templating (think I said this in another thread?) and for content management I can definitely say that a database storage system is a bad idea for you at this time, for your application and your just giving yourself future problems

As for SweatJe's attitude (in other thread) maybe there is nothing wrong with it after all huh...

its just I have not really made any progress with this script and its frustrating.

Quit spending time making your life more difficult then...

What is your definition of "good way to program"? If you're not making progress and it is frustrating you, then I'm guessing it is not a "good way to program" so my advice is to try a different approach. Then you can see if it is a "better" or a "worse" way to program. Once you can compare things, you'll at least have something to work with.

I say its frustrating because when I am asking for help people keep telling me I am doing it wrong. I am not asking for an opinion of my method of implementing my script I am just asking how I could get it done.

I say its frustrating because when I am asking for help people keep telling me I am doing it wrong. I am not asking for an opinion of my method of implementing my script I am just asking how I could get it done.

Your first post seems to ba sking for opinions more than anything else, which is what you've gotten. If you were asking specific things, like "how do I get the template from the Database?" (Use SELECT or check out the API of your chosen ORM/DBAL) or "how do I get the variables into the template?" (eval) then you would probably have still have gotten people saying that you shouldn't put your templates in the database

You can't be stuck on the road with a flat tire and when someone stops to help you out, tell them "well, it is a square wheel that I want to put on my car, so are you gonna help me or not?"; you will more than likely not receive any help, as for anyone with common sense, "help" would be to try and explain to you that a round wheel would work much better. But you don't seem like the type that accepts advice from others, so it's unlikely that you will find any kind of help in these forums with that approach.

I say its frustrating because when I am asking for help people keep telling me I am doing it wrong. I am not asking for an opinion of my method of implementing my script I am just asking how I could get it done.

Perhaps you are in the wrong forum. This forum is for:

1) If you wish to discuss topics such as Object Orientated Programming, Design Patterns and other software development techniques related to PHP then please post in the Advanced PHP Programming forum. If your thread does not deal with the above then the Advanced PHP Programming forum is not what you are looking for.

2) If you need help with a parse error, or would like to know how to achieve something with PHP or have a PHP question that does not fit any other forum then please post in the PHP forum.

Here you get a opinion: like it or not. When smart people disagree with me, I start to listen more closely to what they are saying and try to learn (though I'd never let them know that ... oops, just did)

I'm getting the feeling that we may well have another Tony here folks, and it's just something we got to put up with

Naa, Tony knows he is an a ss. And is proud of it. Ian just likes the relational model much more than the hierarchical filesystem model. He's just putting that preference above the performance/efficiency/ease of coding issues.

I'm saying that because I disagree with the Tony label - file system based templates are the best choice. If you give the files .phtml extensions and put them outside the server's public directory, you'll get the 'beauty' of the DB solution plus the performance too. (It is extensions like .tpl.php which make the filesystem solution ugly imo, along with using too many and too split up templates. Avoid both those problems and you beat the hell out of the 'beauty' of the relational setup!)

Perhaps Ian doesn't view things in terms of beauty, but that's my impression for his motivation to move things into the DB. But beauty comes in performance, not just layout. This is design of dynamic systems, the beauty is in the dynamic not some static flow chart.

Traditional template systems rely on flat-files stored on the server in some folder that holds them, the problem with this is that is, in my opinion, cluttered and bad. I want to be able to create templates in the MySQL database and then have variables in those templates such as

Ian,

I think you're wrong to be worried about the database structure at this point. Just build a simple class that fetches a template based on a key:

So, what I am asking is help with the database structure for MySQL and help with how to implement this templating system.
PLEASE DO NOT TELL ME ABOUT EXISTING TEMPLATE SYSTEMS!!
I already know about them and I am not interested in them, don't make any posts mentioning them PLEASE!!!

Sorry, man:

There are lots of templating systems out there, and they've solved the various "usual problems": template nesting, variable substitution, etc.

You'll be much better served tearing them apart for ideas and implementations than asking here. WACT, which is popular with many of the SP users, might be a good starting point.

This is not to say you have to model your code on any other system, but that you should get your list of features from there. Do a basic use-case analysis to identify the 10 must-have features, and implement them...

File system based templates are simply A choice. Ultimately it does not matter where the template data is stored. I see no reason why you couldn't build you own or use one of the many existing templating systems with templates from any data source.

So, what I am asking is help with the database structure for MySQL and help with how to implement this templating system.

Sure, you could even print them out and OCR them whenever someone wants to visit your site:

Book based:
key - page number
template - page text

... it is also A choice, though not one I would want to use for the average web app. Performance wise, and complexity of code wise, using the file system is the easiest, and using dead trees is the hardest. That's why you see more people talking about using the file system than using paper to store the data.

It really is that simple. That's why I recommended you just wrap it in a class and get on with the interesting stuff.

(Note: There are a lot of cool things you can do with DB based templates -- but none of them come into play until you get "basic" template handling to work. So throw something together, put a big "FIXME: this is trash code" in a comment someplace, and move on to the next use case.)

I'll take back what I said earlier about the new Tony, no hard feelings Ian? If it's just a point of being more in favour of one method over another method then there has to be a reasoning behind it, as choosing a database template method has knock on effects as said

Off Topic:

still not shown to be hazardous.

That what they (Goverment) said about BSE here in the UK and now look, people are dying of a brain disorder That's what happens when you feed cattle dead chickens and why I've never eaten beaf for the last 8 odd years.

That's what happens when you feed cattle dead chickens and why I've never eaten beaf for the last 8 odd years.

Even worse is feeding cattle cattle

Off Topic:

Livingston: BUT, if he then goes on to parade about his DB solution in every second thread as the absolute best despite the obvious dead-chicken problem, then you've got my goahead to call him Tony
(Unless something magic happens when he writes it and it turns out to have the same sort of performance against the expectations of 90% of the people here, in which case I want to know all about how you did it Ian! (though in your own thread please ))

I am wondering about why there was such a violent reaction to a DB Template Storage system. This thread has acutally got me thinking about one of my clients that has an underused backend Postgres server and a heavily used frontend server used for file uploads. I have been thinking that it might make sense to put the template data in the database just to reduce disk activity on the frontend server.

I in general agree that you use file systems for what they are good for and databases for what they are good for. But it is not an absolute rule. Also the advice on layering you application is a good one.