• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to view a XML instead of PHP or HTML file

#1
[eluser]Rubiz'[/eluser]
Hello everyone :-)

I'm trying to view a xml using $this->load->view('folder/test.xml');
I've tryied this too: echo $this->load->view('folder/test.xml'); but the XML really can't be read.

CI does not support this kind of view? if dont't, how could I show this?

Thanxs!

Rúbia

#2
[eluser]iainco[/eluser]
You could have your XML in a PHP file simply with no PHP code.

Rename test.xml to test.php, then you can use the code

Code:
$xml = $this->load->view('folder/test', $data, TRUE);

You might not need to pass any data to the view with the $data var.

The last arg TRUE ensures the view contents are returned instead of being output to the browser.

#3
[eluser]attos[/eluser]
I use CI to provide a RSS feed using Derek Allard's tutorials.
It's avalable from his site.
I had an issue with the view with the closing xml tag.
I had to replace it with
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
echo "<?xml version=\"1.0\" encoding=\"utf-8\" \x3F>\n"
?>
This is a known issue documented here.

#4
[eluser]Phil Sturgeon[/eluser]
[quote author="attos" date="1227666792"]I use CI to provide a RSS feed using Derek Allard's tutorials.
It's avalable from his site.
I had an issue with the view with the closing xml tag.
I had to replace it with
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
echo "<?xml version=\"1.0\" encoding=\"utf-8\" \x3F>\n"
?>
This is a known issue documented here.[/quote]

Put the code above at the top of your view file, and add the following in your controller to set the headers correctly.

Code:
$this->output->set_header('Content-Type: text/xml; charset=ISO-8859-1');

Make sure that's done before your view file, and before any content is being output. If you do have anything being output, you'll need to clear the output buffer (wipe the screen), which can be done with:

Code:
while (@ob_end_clean());


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.