Skip to main content
Inspiring
October 12, 2006
Question

building a cfc that creates an RSS feed

  • October 12, 2006
  • 1 reply
  • 919 views
I am attempting to build a cfc that will create an RSS feed for me. my thought is that i feed i pass in a query object, the feed title, link and description and then the names of the query feilds that corrrespond to the item title, link and description.

that way the cfc would loop through the passed query and build each <item> with the correct data for title, link and description based on the feilds from the database which were identified in the CFC arguments. for instance, lets say i have a db table with news stories that looks like this:

tblStories
ID int PK
Title char 30
Link char 50
Description char 100

then i would invoke my cfc like this:
<CFQUERY name="stories">
SELECT *
FROM tblStories
</CFQUERY

<cfobject component="RSS_build" name="rssObj" />
<cfinvoke component="#variables.rssObj#" method="buildRSS" returnvariable="returnString">
<cfinvokeargument name="FeedQuery" value="#stories#">
<cfinvokeargument name="feedtitle" value="My news Feeds">
<cfinvokeargument name="feedLink" value=" http://www.mynewsfeeds.com/index.cfm?RSS=true">
<cfinvokeargument name="feedDescription" value="List of the items features on the homepage of mynewsfeeds.com">

<cfinvokeargument name="itemtitleField" value="Title">
<cfinvokeargument name="itemlinkField" value="Link">
<cfinvokeargument name="itemdescriptionField" value="Description">
</cfinvoke>

Then inside my CFC is where this gets kind of tricky. when i want to look through the passed query i am nto sure how i would access the feilds i want.
<cfloop query="mypassedQuery">
<title>mypassedquery.#arguments.itemtitleField#</title>
</cfloop>

but this outputs mypassedquery.Title. instead ov actually finding the value of mypassedquery.Title.

am i totally goign about this the wrong way? is there a better way to do this?
    This topic has been closed for replies.

    1 reply

    Inspiring
    October 12, 2006
    Not to bash your effort, I often re-invent the wheel so I know how the
    wheel works, but Ray Camden as already create a CFC that creates RSS
    feeds. It was just recently discussed on the CF-Talk list at
    HouseOfFusion.com
    bdee2Author
    Inspiring
    October 12, 2006
    thanks for the reply - i found Ray's CFC and although it will help me, i still woudl prefer to build my own. the primary reason is that i want a simple cfc that i can just pass a query object into. with Ray's you have to either build the query as he did in his test file or be sure that the query columns are named appropriately.

    my intention is to be able to pass in any query with any column names and then just identify the column names in the arguments.

    with that said, how woudl i get my example to read a query column properly. esentially i want to say #Attributes.query#.#attributes.title# and have it accurately pull the data from the query object's column that was specified as containing the title information.
    bdee2Author
    Inspiring
    October 12, 2006
    got it! I forgot that to access a variable in a variable you can use bracket notation.

    so to express #Attributes.query#.#attributes.title# the way i want i need to say
    #Arguments.feedQuery[arguments.itemtitleField][arguments.feedquery.currentrow]#

    if this were a struct I would just do one set of brackets but because its a query i have to add the second set of brackets which specify the row number.