How do I configure CFWheels to display the following XML at http://mydomain.com/sitemap.xml?
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<-- I'll add the <url> tags dynamically here later -->
</urlset>
I've removed the "sitemap.xml" from the web.config file.
After this I'm not sure what to do about creating the controller and view. Should I create a "sitemap.xml" folder in the "views" folder, then add an "index.cfm" file and then add the XML above?
Should I create a "sitemap.xml.cfc" file in the "controllers" folder? And what should the controller file contain?
Should it look something like this?
<cfcomponent extends="Controller" output="false">
<cfscript>
function init(){
// Let CFWheels know what type of output this controller can 'provide'
provides("xml");
}
function index(){
}
</cfscript>
</cfcomponent>
Do I need to add an entry to the routes.cfm?
Setting up the Controller
Your controller's
index()method should look something like this. It's stored atcontrollers/Sitemap.cfc.Setting up the View
Your view at
views/sitemap/index.xml.cfmcan then generate the required XML:Then you can implement a partial at
views/sitemap/_url.xml.cfmrepresenting a single item in your query or array. Let me know if you're using something other than a query, and I can modify my example above.Keep in mind that when you use a partial like this, query columns or struct keys get placed into the
argumentsscope, which is why I'm referencingarguments.uriandarguments.updatedAtin my fictitious example.Accessing via URL
Depending on your server's URL rewriting capabilities, you may need to try a couple things to get the URL to do what you want.
You may be able to do something like this in
config/routes.cfm(but I've only tested this on Apache):Then you can load the URL at
http://www.example.com/sitemap.xmlIf that doesn't work, try this:
Again, you can load the URL at
http://www.example.com/sitemap.xmlFinally, if that doesn't work, remove the extra lines from
config/routes.cfmand load this URL (which most definitely will always work regardless):