I’m writing a PHP application using codeigniter framework. I’m trying to add a tool to download the data in the page as a .csv format file. I have the code to the server side, but I’m having trouble handling the URL mapping for the “Download” Controller.
in /controllers/ I have a controller called “Download”, which is has a function called ‘exportCSV’, which receives a json object that is decoded and used to create the file. So, I’m trying to send a JavaScript array through ‘post’ to that method, but I’m having trouble handling the URL mapping.
here is my javascript call …
function download(){
$.post('index.php/download/exportCSV', {input : dataForDownload.toString()},
function(answer){
alert(answer);
}
);
}
POST to
index.php/download/exportcsv. CI doesn’t much like Mixed Case controllers.If you have a download controller, it should look like this:
class Download extends CI_Controller
{
function _construct()
{
parent::_construct();
}
}
If you’re getting a 404, your application might not be set up correctly. Check
routes.phpand yourbase_url.I also recommend the CodeIgniter user guide. It’s full of good information: