Simple DataTablesMySqlQuery class for Symfony
Simple DataTablesMySqlQuery class for Symfony
jzohrab
Posts: 20Questions: 1Answers: 0
Hi all,
I had a few datatables pages in my symfony project that were backed by ajax-mysql queries. Existing symfony examples or packages were too complicated to follow or had issues, so I wrote a simple thing that lets my Repository class return the data for my DataTables to consume:
// In Repo class:
/** Returns data for ajax paging. */
public function getDataTablesList($parameters) {
$base_sql = "SELECT
fieldA, fieldB, fieldC, etc etc etc ... etc.
";
$conn = $this->getEntityManager()->getConnection();
// helper works with the base sql and params to return what's needed.
return DataTablesMySqlQuery::getData($base_sql, $parameters, $conn);
}
The code, with some tests and a twig sample, is in this gist. If it helps you, please steal it and take all the credit for it. :-P
Cheers! jz