[eluser]Unknown[/eluser]
hai.....i got the error like You must submit a valid result object.AND my code is
view:
<!DOCTYPE html>
<html>
<head>
<title>CodeIgniter and jQuery rocks.</title>
[removed][removed]
[removed][removed]
</head>
<body>
<button id="download">Download file</button>
</body>
</html>
CONTROLLER:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dashboard extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->helper('url');
$this->load->view('index');
}
public function download()
{
$this->load->model('users_m');
$this->load->dbutil();
$this->data['users']= $this->users_m->get_users();
$users= $this->data['users'];
$delimiter = ",";
$newline = "\r\n";
$this->output->set_header('Content-Type: application/force-download');
$this->output->set_header('Content-Disposition: attachment; filename="registered_users.csv"');
$this->output->set_content_type('text/csv')
->set_output($this->dbutil->csv_from_result($users, $delimiter, $newline));
}
}
model:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Users_m extends CI_Model {
public function get_users()
{
$q = $this->db->select('users.name, users.surname, users.email')
->from('users')
->get();
return $q->result();
}
}
script.js:
$(function() {
$('#download').click(function(event) {
event.preventDefault();
document.location.href = 'http://localhost/CI/index.php/dashboard/download';
});
});