views:

79

answers:

2

So, currently I'm organizing my blog based on filename: To create a post I enter the name of the file. As opposed to storing the post in the database, I store them in PHP files. So each time I create a post, A new row in the table is created with the filename and a unique ID. To reference the post (e.g. for comments) I get the name of the current file, then search the entries table for a matching file name. The post ID of the comment matches the ID of that post.

Obviously this isn't the standard way of organizing a blog, but I do it this way for a few reasons:

  • Clean URL's (even cleaner than mod_rewrite can provide from what I've read)
  • I always have a hard copy of the post on my machine
  • Easier to remember the URL of a specific post (kind of a part of clean URL's)

Now I know that the standard way would be storing each post in the database. I know how to do this, but the clean URL's is the main problem. So now to my questions:

  • Is there anything WRONG with the way I'm doing it now, or could any problems arise from it in the future?
  • Can the same level of clean URL's that I can get now be achieved with mod_rewrite? If so, links are appreciated
  • I will be hosting this on a web host. Do only certain web-hosts provide access to the necessary files for mod_rewrite, or is it generally standard on all web-hosts?

Thanks so much guys!

P.S. To be clear, I don't plan on using a blogging engine.

+1  A: 

What you're describing is kind of like how Movable Type works. The issues you'll need to cover are:

  • Syndication: RSS/Atom;
  • Sitemap: for Google;
  • Commenting; and
  • Tagging and filtering content.

It's not unreasonable not to use a database. If I were to do that I'd be using a templating engine like Smarty that does a better job of caching the results than PHP will out of the box.

cletus
Ok, I haven't thought about RSS, yet. As for a sitemap, I usually just use an automated sitemap generator. Will this be a problem? I have commenting and tagging figured out.
WillyG
Also, can you elaborate on what you were talking about "caching the results" (I'm kind of a newbie :P)
WillyG
+2  A: 

As cletus said, this is similar to Movable Type. There's nothing inherently wrong with storing your data in files.

One thing that comes to mind is: how much are you storing in the files? Just the post content, or does each PHP file contain a copy of the entire design of the page as opposed to using a base template? How difficult would it be to change the design later on? This may or may not be a problem.

What exactly are you looking for in terms of clean URLs? Rewrite rules are quite powerful and flexible. By using mod_rewrite in conjunction with a main PHP file that answers all requests, you can pretty much have any URL format you want, including user-friendly URLs without obscure ID numbers or even file extensions.

Edit:

Here is how it would work with mod_rewrite and a main PHP file that processes requests:

  1. Web server passes all requests (e.g., /my-post-title) to, say, index.php
  2. index.php parses the request path ("my-post-title")
  3. Look up "my-post-title" in the database's "slug" or "friendly name" (whatever you want to call it) column and locates the appropriate row that way
  4. Retrieve the post from the database
  5. Apply a template to the post data
  6. Return the completed page to the client

This is essentially how systems like Drupal and WordPress work.

Also, regarding how Movable Type works, it's been a while since I've used it so I might be wrong, but I believe it stores all posts in the database. When you hit the publish button, it generates plain HTML files by pulling post data from the database and inserting it into a template. This is incredibly efficient when your site is under heavy load - there are no scripts running when a visitor opens up your website, and the server can keep up with heavy visitation when it only needs to serve up static files.

So obviously you've got a lot of options when figuring out how your solution should work. The one you proposed sounds fine, though you might want to give careful consideration to how you'll maintain a large number of posts in individual files, particularly if you want to change the design of the entire site later on. You might want to consider a templating engine like Smarty, and just store post data (no layout tags) in your individual files, for instance. Or just use some basic include() statements in your post files to suck in headers, footers, nav menus, etc.

Jeff
ideally, I'd like URL's like www.DOMAINNAME/post-title-hereI don't mind file extensions but obviously less is more. Is there a way to do this with mod_rewrite and do most webhosts let you?I plan on storing the content and the design in each file. I can't think of another way to do it without pulling info from a database...
WillyG
In my experience with 3 major web hosts, I've always had the necessary permissions to use a .htaccess file to specify all the rewrite rules I need. It seems like such a basic requirement, I'd be surprised if a host didn't allow it. Of course, it depends on the individual web host, but they'll tell you whether or not it's supported. As for your other questions, I'll edit my post to answer those...
Jeff