Last active
January 16, 2022 17:23
-
-
Save n1crack/38860d78db4bf6522391238e0feab2e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
// Codeigniter 3 usage : | |
// Set config/config.app: | |
// $config['composer_autoload'] = 'vendor/autoload.php'; | |
use Ozdemir\Datatables\Datatables; | |
use Ozdemir\Datatables\DB\CodeigniterAdapter; | |
class Welcome extends CI_Controller { | |
public function index() | |
{ | |
$this->load->view('welcome_message'); | |
} | |
public function ajax() | |
{ | |
$datatables = new Datatables(new CodeigniterAdapter); | |
$datatables->query('Select film_id, title, description from film'); | |
echo $datatables->generate(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controllers; | |
use Config\Database; | |
use Ozdemir\Datatables\Datatables; | |
use Ozdemir\Datatables\DB\Codeigniter4Adapter; | |
class Home extends BaseController | |
{ | |
public function index() | |
{ | |
return view('welcome_message'); | |
} | |
public function ajax() | |
{ | |
// CI 4 builder class | |
$db = Database::connect(); | |
$builder = $db->table('Track'); | |
$builder->select('TrackId, Name, UnitPrice'); | |
// Datatables Php Library | |
$datatables = new Datatables(new Codeigniter4Adapter); | |
// using CI4 Builder | |
$datatables->query($builder); | |
// alternatively plain sql | |
// $datatables->query('Select TrackId, Name, UnitPrice from Track'); | |
return $this->response->setJSON($datatables->generate()->toJson()); | |
// or | |
// echo $datatables->generate(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// example route file | |
use Ozdemir\Datatables\Datatables; | |
use Ozdemir\Datatables\DB\LaravelAdapter; | |
Route::get('/', function () { | |
return view('welcome'); | |
}); | |
Route::get('ajax', function () { | |
$datatables = new Datatables(new LaravelAdapter); | |
$datatables->query('Select film_id, title, description from film'); | |
return $datatables->generate(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Define route | |
// ... | |
$router->add( | |
"/", [ | |
"controller" => "home", | |
"action" => "index" | |
] | |
); | |
$router->add( | |
"/ajax", [ | |
"controller" => "film", | |
"action" => "ajax" | |
] | |
); | |
// Define film controller | |
// ... | |
use Ozdemir\Datatables\Datatables; | |
use Ozdemir\Datatables\DB\PhalconAdapter; | |
Class FilmController extends Controller { | |
// ... | |
public function AjaxAction() { | |
$datatables = new Datatables(new PhalconAdapter($this->di, 'db')); | |
$query = $this->modelsManager->createBuilder() | |
->columns('film_id, title, description') | |
->from('App\Models\Film') | |
->getQuery() | |
->getSql(); | |
$datatables->query($query['sql']); | |
return $datatables->generate(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Ozdemir\Datatables\Datatables; | |
use Ozdemir\Datatables\DB\PSAdapter; | |
/** | |
* Example for Prestashop FrontController | |
*/ | |
class ModuleNameControllerNameModuleFrontController extends ModuleFrontController | |
{ | |
public function displayAjaxDatatableResults() | |
{ | |
$dt = new Datatables(new PSAdapter([])); | |
$dt->query('SELECT * FROM ' . _DB_PREFIX_ . '_table'); | |
return $dt->generate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment