Welcome Guest, Not a member yet? Register   Sign In
Save as XML file
#1

[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>
    
    &lt;title&gt;&lt;?php echo $feed_name; ?&gt;&lt;/title&gt;

    &lt;link&gt;&lt;?php echo $feed_url; ?&gt;&lt;/link&gt;
    <description>&lt;?php echo $page_description; ?&gt;</description>
    <dc:language>&lt;?php echo $page_language; ?&gt;</dc:language>
    <dc:creator>&lt;?php echo $creator_email; ?&gt;</dc:creator>

    <dc:rights>Copyright &lt;?php echo gmdate("Y", time()); ?&gt;</dc:rights>

    &lt;?php foreach($products as $item){ ?&gt;
    
        <item>

          &lt;title&gt;&lt;?php echo xml_convert($item->product_name); ?&gt;&lt;/title&gt;
          &lt;link&gt;http://www.mydomain.com/&lt;?=$item->category_slug?&gt;/&lt;?=$item->product_slug?&gt;&lt;/link&gt;
          <guid>http://www.mydomain.com/&lt;?=$item->category_slug?&gt;/&lt;?=$item->product_slug?&gt;</guid>
          <description>&lt;?php echo xml_convert($item->product_desc); ?&gt;</description>
          <g:image_link>http://www.mydomain.com/images/products/&lt;?=$item->product_image1?&gt;</g:image_link>
            <g:price>&lt;?=$item->product_price?&gt;</g:price>
            <g:condition>new</g:condition>
            <g:id>&lt;?=$item->product_id?&gt;</g:id>
        </item>
        
    &lt;?php endforeach; ?&gt;

        </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.
#2

[eluser]LuckyFella73[/eluser]
Quote:I would like it to make an xml file

What you are doing now is parsing xml to the browser. If
you need a file you can use the file helper to write
the stuff into a file.




Theme © iAndrew 2016 - Forum software by © MyBB