Viewing Individual Entry / Main
  ::   May 22, 2003

Extending Raymond Camden's blog.cfc
If you aren't already aware, I run the www.CFCZone.org Blog using a modified version of Raymond Camden's blog.cfc. Originally, I made several modifications to his core CFC to suit my needs. This soon became a problem, however, as each time Ray released a new version of his blog.cfc (either new features or bug fixes), I had to manually go through my version and compare it with his and try to incorporate the changes. Additionally, because Ray sets site specific variables in the "constructor" area of the CFC, you can't just replace your current blog.cfc with an updated version without copying and pasting your constructor code first. There is a better way.

The solution is to treat Ray's blog.cfc as a base component, and extend it with your own sub component. Your sub component should contain code that overrides the values set in Ray's constructor with your own. It can also contain your own version of any methods you want to behave differently than the versions Ray wrote. Additionally, if you want to add any new functionality to the blog.cfc without actually updating the base CFC, you can do it in the one you create.

In my case, I wanted a different version of the generateRSS() method found in blog.cfc. So, I created my sub component, called roBlog.cfc Here's the code for it:















hint="Attempts to generate RSS 1.0">







xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns="http://purl.org/rss/1.0/">


#blogTitle#
#blogDescription#
#blogURL#











  • #xmlFormat(title)#
    #xmlFormat(left(body,250))#...#xmlFormat(body)#
    #blogURL#?#xmlFormat("#blogItemURLPrefix##id#")#
    #dateStr#








    In my CFC, all of my "constructor" code overrides the values set in the base CFC. This way, Ray can modify his CFC anytime he wants and I can upddate it on my site without having to worry about changing the values in the file. The only other thing to note is that instead of calling blog.cfc in all of my actual application code, I now call roBlog.cfc, since it's the main CFC and inherits everything else from blog.cfc.

    As for the difference between my generateRSS() and Ray's? There are really two. First, my version uses the cfxml tag instead of the cfsavecontent technique Ray uses. The second difference is that my generateRSS() is context sensitivite. It allows you to generate a different RSS feed depending on what view of the blog you are in. So, on the main page, you get an RSS feed for the last 30 days worth of posts (the default). If you want an RSS feed of only CF related posts, all you need to do is click on the ColdFusion Category link, then click the XML button on that page.



  • Calendar
    Sun Mon Tue Wed Thu Fri Sat
              1 2
    3 4 5 6 7 8 9
    10 11 12 13 14 15 16
    17 18 19 20 21 22 23
    24 25 26 27 28 29 30
    31            

    Recommended Reading
    Programming ColdFusion MX, 2nd Edition

    Archives by Subject
    Announcements (28)
    ColdFusion (61)
    Database (12)
    Dreamweaver (1)
    Flash (2)
    Flash Remoting (2)
    Flex (3)
    General Development (2)
    Homesite + (1)
    Mach-II (3)
    MAX (9)
    Mozilla (2)
    Music (1)
    Politics (1)
    Portals (2)
    Travel (2)

    Search

    Links
    CFLib.org
    Raymond Camden's Blog
    Christian Cantrell's Blog
    Sean Corfield's Blog
    Nathan Dintenfass' Blog
    Todd Rafferty's Blog
    Steve Rittler's Blog
    Cameron Childress's Blog

    Credits
    Based on blog.cfc by Raymond Camden

    XML Feed