Ignited Datatables + Codeigniter - How to specify database

Ignited Datatables + Codeigniter - How to specify database

baytesbaytes Posts: 11Questions: 0Answers: 0
edited March 2013 in General
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!

Replies

  • baytesbaytes Posts: 11Questions: 0Answers: 0
    Anyone have any ideas? I've added another db connection in database.php but im not sure how to have datatables use it instead of $db. any thoughts?
  • kawikakawika Posts: 4Questions: 0Answers: 0
    From the Datatables.php library for codeigniter:

    [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]
  • baytesbaytes Posts: 11Questions: 0Answers: 0
    Thank you for your reply.

    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!
  • kawikakawika Posts: 4Questions: 0Answers: 0
    the function is already set to provide that functionality, the code would be something like this:

    [code]
    $this->datatables->set_database('db2');
    [/code]

    then you could act on whatever database you set...
  • baytesbaytes Posts: 11Questions: 0Answers: 0
    do i use that in replace of

    $db_data = $this->ci->load->database($db_name, TRUE);
    $this->ci->db = $db_data;

    ?

    completly confussed
This discussion has been closed.