I am trying to load a flat text file into a controller. I understand that I need to use the Loader function to do it (and set the second parameter to true to get a string back) but no matter what path I use, Loader cannot find the file. Where is the top of the file_path?
$this->load->file('../application/views/textiles/about.txt',true);
It would also be nice to know how I set this loaded string to a variable to be passed to a view.
Update
I should add, that I just found something that works equally well as Jordan’s solution for what I am attempting to do. The text file is written in markdown and so to convert it for the view, you can also do the following (and worry less about the file path):
$this->load->helper('markdown');
$string = $this->load->view('text.txt', '', true);
$string = markdown($string);
$data['text'] = $string;
$this->load->view('template', $data);
The top of the
file_pathis in your document root. If you need to access a file insideapplication/viewswrite:It’s best to use
APPPATHas shown, in case you ever decide to change your directory structure and reroute it inindex.php. Note, if you’re on a *NIX box, you’ll need to grant the appropriate permissions to this directory/file.Then in your view, you would access the file simply using
$file_contents.