Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I view an XML file in browser using Codeigniter

Ok, I have looked around, and I can't seem to figure this out.

Here is my CodeIgniter Structure:

  • orders
    • application
      • controller
      • model
      • view
    • xml

As you can see, the XML folder is outside the application folder. Inside the XML folder I have an xml file named example.xml. Inside the controller, how do I load the xml file to view it in the browser?

class Example extends CI_Controller {
   public function view_xml(){
       header("Content-type: text/xml");
       $this->load->view() ??????? // Here is where I'm stuck
   }
}

I have tried using BASEPATH and $_SERVER['DOCUMENT_ROOT'] but with no luck. I want to be able to type in the url example/view_xml to view the xml in the browser.

like image 656
FNMT8L9IN82 Avatar asked Sep 01 '25 01:09

FNMT8L9IN82


1 Answers

Never mind, I figured it out. Instead of using CodeIgniter's $this->load->view(), I just load the file and echoed it out to the screen.

public function view_xml(){
   header("Content-type: text/xml");
   $xml_file = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/xml/example.xml");
   echo $xml_file;
}
like image 91
FNMT8L9IN82 Avatar answered Sep 02 '25 17:09

FNMT8L9IN82