Ignited Datatables + Codeigniter - How to specify database
Ignited Datatables + Codeigniter - How to specify database
How can i specify which database to use using Ignited datatables library and codeigniter below is my code:
site.php - controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller {
public function index()
{
$this->load->view('post');
}
public function getdatabyajax()
{
$this->load->library('Datatables');
$this->datatables
->select('username,email,salt')
->from('users');
echo $this->datatables->generate();
}
}
post.php - view
.....
.....
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "<?php site_url(); ?>index.php/site/getdatabyajax",
"sServerMethod": "POST"
} );
} );
.....
.....
Username
Email Address
Salt
Loading data from server
.......
......
any help is greatly appreciated!
site.php - controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller {
public function index()
{
$this->load->view('post');
}
public function getdatabyajax()
{
$this->load->library('Datatables');
$this->datatables
->select('username,email,salt')
->from('users');
echo $this->datatables->generate();
}
}
post.php - view
.....
.....
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "<?php site_url(); ?>index.php/site/getdatabyajax",
"sServerMethod": "POST"
} );
} );
.....
.....
Username
Email Address
Salt
Loading data from server
.......
......
any help is greatly appreciated!
This discussion has been closed.
Replies
[code]
/**
* If you establish multiple databases in config/database.php this will allow you to
* set the database (other than $active_group) - more info: http://codeigniter.com/forums/viewthread/145901/#712942
*/
public function set_database($db_name)
{
$db_data = $this->ci->load->database($db_name, TRUE);
$this->ci->db = $db_data;
}
[/code]
in datatables.php it already has both of those lines added.
Are you saying, change $db_name in the first line:
$db_data = $this->ci->load->database($db_name, TRUE);
to
$db_data = $this->ci->load->database('db2', TRUE);
?
Thanks for your help!
[code]
$this->datatables->set_database('db2');
[/code]
then you could act on whatever database you set...
$db_data = $this->ci->load->database($db_name, TRUE);
$this->ci->db = $db_data;
?
completly confussed