[eluser]ukCIdeveloper[/eluser]
Hi there,
I'm trying to create an XML feed of my products for Google Base. When I visit
http://mydomain.com/feed/google, I would like it to make an xml file like
http://mydomain.com/feed/google.xml.
My current controller looks like this;
Code:
<?php
class Feeds extends Controller
{
function Feeds()
{
parent::Controller();
$this->load->helper('xml');
$this->load->helper('text');
$this->load->model('products_model', '', TRUE);
}
function google()
{
$data['feed_name'] = 'mydomain.com'; // your website
$data['encoding'] = 'utf-8'; // the encoding
$data['feed_url'] = 'http://www.mydomain.com/feeds/google'; // the url to your feed
$data['page_description'] = 'Product feed'; // some description
$data['page_language'] = 'en-en'; // the language
$data['creator_email'] = '[email protected]'; // your email
$data['products'] = $this->products_model->getAllProducts();
header("Content-Type: application/rss+xml");
$this->load->view('feeds/google', $data);
}
}
?>
My current view file looks like this:
Code:
<?php
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:admin="http://webns.net/mvcb/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title><?php echo $feed_name; ?></title>
<link><?php echo $feed_url; ?></link>
<description><?php echo $page_description; ?></description>
<dc:language><?php echo $page_language; ?></dc:language>
<dc:creator><?php echo $creator_email; ?></dc:creator>
<dc:rights>Copyright <?php echo gmdate("Y", time()); ?></dc:rights>
<?php foreach($products as $item){ ?>
<item>
<title><?php echo xml_convert($item->product_name); ?></title>
<link>http://www.mydomain.com/<?=$item->category_slug?>/<?=$item->product_slug?></link>
<guid>http://www.mydomain.com/<?=$item->category_slug?>/<?=$item->product_slug?></guid>
<description><?php echo xml_convert($item->product_desc); ?></description>
<g:image_link>http://www.mydomain.com/images/products/<?=$item->product_image1?></g:image_link>
<g:price><?=$item->product_price?></g:price>
<g:condition>new</g:condition>
<g:id><?=$item->product_id?></g:id>
</item>
<?php endforeach; ?>
</channel></rss>
However, Google Base requires you to actually have a file extension of .xml. So i'm wondering if anyone might have any ideas on how I could extend this to save out an xml file?
Thank you.