SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Storing Templates In MySQL

    I've search for discussions on this topic but I didn't see my exact situation.

    Basically, I want to use templates for my site, but I want to store the templates in MySQL. It doesn't have be as sophisticated as vBulletin, but it should allow me to just edit the row and save it.

    Any help is appreciated.
    <///////~

    www.sohh.com

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why would you want to put it in a DB ?

  3. #3
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thought that I have been having is that a database would (might?) be suitable if you have one template (structural) and several others, one per language, you could pull out the structural one along with the correct language template in one go?

    I'm not too keen on putting templates to a database either, but I just had that thought I suppose

  4. #4
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    Why would you want to put it in a DB ?
    Well, I would want to put it in a db for a few reasons.

    1. My site is powered by a CMS, so I'd like to allow administrators to change up the templates themselves.

    2. There are times when I want to make a change and don't want to hassle with FTP. I'd rather edit it right there on the spot.

    3. Right now, I'm using templates as file, but for reasons 1 and 2 AND having to remember which template is which is becoming a problem.
    <///////~

    www.sohh.com

  5. #5
    SitePoint Enthusiast mjlivelyjr's Avatar
    Join Date
    Dec 2003
    Location
    Post Falls, ID, US
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure that I would ever put a template itself into a database. It would add a bunch of blobs to your database and I could see it suffering from the same issues that come up when storing images (the actual image, not a reference to a file) in a database.

    If you want to just allow your cms administrators pick from predefined templates than all you really should need is a field in your database to store a path to a directory containing the given set of template files. Exactly where in the database this would go depends on your implementation. If each administrator has their own semi-indepent cms driven site I would say it would be in whatever table manages each of these individual cms systems. There are lots of different scenarios as far as your implementation goes though, so that is the only guess in regards to placement I am going to make.

    Now, if you want your administrators to be able to edit/create their own templates than I would STILL recommend only holding a reference to a file in the database. This will keep performance from suffering on the DB server as chances are template files/strings will become one of the LEAST changed aspects of the database. So I would still keep the templates stored in the file system but reference them from the database. I guess the best way to think about it is that you would treat them like you do images in a product catalog.

  6. #6
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Devil's advocate...

    If putting templates in a db is so bad, why do products like vBulletin and phpBB continue to do it?
    <///////~

    www.sohh.com

  7. #7
    SitePoint Enthusiast mjlivelyjr's Avatar
    Join Date
    Dec 2003
    Location
    Post Falls, ID, US
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I could be wrong but I am pretty sure phpBB doesn't store templates in the db. It DOES store references to template files as well as variables to be used in the templates (ie. table row colors, font info, etc.) As far as whether or not vBulletin does it I honestly cannot say, I have never done any installation or maintenance of that script myself.

    One thing that should be kept in mind is that just because a popular, open-source piece of software does something a certain way doesn't necessarily mean it's right. Most open source projects have tens of developers all working in different areas, they all have different backgrounds, and they all do something different ways. Some of them do things very well and are smart with their code and some are still in that 'learning' phase. I have worked on a few open source projects myself as well as many, many closed source projects. I have done some things I am extremely proud of and some things I look back at and say to myself "what was I thinking?" My bet is if I look back at some of those projects where I implemented bad code that code would still be there. Mostly because the code, while ugly and inefficient, still worked and partly because lots of open-source developers have the mentality of "if it ain't broke, don't fix it." That is until you come to a major version change. In any case, my point is don't turn to open-source software for definitive answers on how to solve problems.
    Mike Lively
    Digital Sandwich - MMM MMM Good

  8. #8
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    phpBB doesn't store templates in db, just as Mike says. Using phpBB as an example of how to do things right, is probably questionable anyway, but at this point, they don't mess up.

  9. #9
    SitePoint Enthusiast mjlivelyjr's Avatar
    Join Date
    Dec 2003
    Location
    Post Falls, ID, US
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was going to mention the same thing about phpBB kyber* but I thought it would just be mean
    Mike Lively
    Digital Sandwich - MMM MMM Good

  10. #10
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can handle setting up my db to save the filename and stuff in the db.

    BUT what about templates that have forms in them. Specifically, a form with a textarea tag. Maybe I'm thinking about it too much, but let's say I call up my template and it has the following code:

    Code:
    <form><textarea>Something</textarea></form>
    When I pull this code into the CMS textarea would the FIRST TEXTAREA close up the box?
    <///////~

    www.sohh.com

  11. #11
    SitePoint Enthusiast mjlivelyjr's Avatar
    Join Date
    Dec 2003
    Location
    Post Falls, ID, US
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whenever you pull anything into a text area you want to make sure you escape any special characters.

    This can be accomplished in straight php code with the function: htmlspecialchars()

    This will allow you to use the characters ",',&,> and < without it causing any adverse effects.
    Mike Lively
    Digital Sandwich - MMM MMM Good


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •