-
-
Notifications
You must be signed in to change notification settings - Fork 2
Add Your Data
Jorge Reyes edited this page Jun 3, 2015
·
2 revisions
Create an event handler feed.cfc with the code below and save it to the handlers directory. In the code you will notice there are four functions which should be self explanatory. The rss function reads the feed XML file and displays it on screen as RSS+XML content. While the generate function sets the feed's Metadata. This Metadata is set to the rc.feed structure. The feed items are set to rc.feed.items with the content fetched from the model feeditems.generateItems(). The ColdBox plug-in feedGenerator() is then called to convert the CFML structure/query data into a RSS formatted XML file. This file is saved to includes\xml\my_first_feed.xml.
<cfcomponent name="feed" output="false" extends="coldbox.system.eventhandler" autowire="true">
<--- Dependencies --->
<cfproperty name="feeditems" type="Model" scope="instance" />
<cffunction name="init" access="public" returntype="feed" output="false">
<cfargument name="controller" type="any"/>
<cfset super.init(arguments.controller)/>
<--- Any constructor code here --->
<cfreturn this>
</cffunction>
<--- By default, run rss event --->
<cffunction name="index" access="public" returntype="void" output="false">
<cfargument name="Event" type="any"/>
<cfset var rc = Event.getCollection()/>
<cfset runEvent("feed.rss")/>
</cffunction>
<--- Display Feed --->
<cffunction name="rss" access="public" returntype="void" output="false">
<cfargument name="event" type="any">
<cfset var rc = event.getCollection()/>
<--- get feed xml file --->
<cfset rc.feedasxml = getPlugin('utilities').readFile('#getSetting("ApplicationPath")#includes\xml\my_first_feed.xml')/>
<--- view --->
<cfset event.setView('vwDisplayFeed')/>
</cffunction>
<--- Create Feed --->
<cffunction name="generate" output="false" returntype="void">
<cfargument name="event" type="any">
<cfset var rc = event.getCollection()/>
<--- feed structure --->
<cfset rc.feed = structNew()/>
<--- metadata --->
<cfset rc.feed["Description"] = "This is an example feed showing the very basics of what constitutes a web feed"/>
<cfset rc.feed["Link"] = "http://www.example.com"/>
<cfset rc.feed["Title"] = "ColdBox Starter Feed"/>
<--- Item's data --->
<cfset rc.feed["items"] = instance.feeditems.generateItems()/>
<--- Process and compile the feed --->
<cfset rc.compileFeed = getPlugin('feedGenerator').createFeed( FeedStruct=rc.feed, OutputFile='#getSetting("ApplicationPath")#includes/xml/my_first_feed.xml' )/>
<-- vview --->
<cfset event.setView('vwGenerateFeed')/>
</cffunction>
</cfcomponent>
- Feed Reader * [RSS Syndication Format](https://github.com/ColdBox/cbox-feeds/wiki/RSS Syndication Format) * RDF Syndication Format * Atom Syndication Format * Supported Syntax and Formats
- Feed Generator
- Feed Generator Elements