Welcome Guest, Not a member yet? Register   Sign In
ERROR : You must submit a valid result object
#1

[eluser]Unknown[/eluser]
hai.....i got the error like You must submit a valid result object.AND my code is


view:


<!DOCTYPE html>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;CodeIgniter and jQuery rocks.&lt;/title&gt;
[removed][removed]
[removed][removed]
&lt;/head&gt;

&lt;body&gt;

<button id="download">Download file</button>

&lt;/body&gt;
&lt;/html&gt;



CONTROLLER:


&lt;?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:

&lt;?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';
});

});




Theme © iAndrew 2016 - Forum software by © MyBB