n1crack / datatables

Simplify your Datatables server-side processing effortlessly using our lightning-fast PHP library, streamlining your workflow seamlessly.
https://datatables.ozdemir.be/
MIT License
266 stars 89 forks source link

Need Column name return #68

Closed fgc0109 closed 3 years ago

fgc0109 commented 3 years ago

I only want use this lib with php ,no js ,no ajax,no request, just php just connect database and use query at version 1.7 it is easy to use but now

https://github.com/n1crack/datatables/blob/3860416c134ee576a5240ce053af71ea814fa56a/src/Datatables.php#L215

$keys = $this->builder->isDataObject() ? $this->columns->names() : array_keys($this->columns->names());

this determine statements is false :

$this->builder->isDataObject()

in that function :

https://github.com/n1crack/datatables/blob/3860416c134ee576a5240ce053af71ea814fa56a/src/QueryBuilder.php#L113

if (!$this->options->columns()) { return false; }

it return false , i need add request/options everywhere? i just use it with php,no request,no json no js no ajax ,pure php

then I try add options

return array_intersect($data, $rangeSet) !== $data;

still false

false false false false false false false false forever false forever return this one

array_keys($this->columns->names());

so nerver output column name

i only need give me names $this->columns->names()

n1crack commented 3 years ago

You can manually change this line: https://github.com/n1crack/datatables/blob/3860416c134ee576a5240ce053af71ea814fa56a/src/QueryBuilder.php#L72

to:

$this->dataObject = true;

by the way if you need only column names, there is a helper method here: https://github.com/n1crack/datatables/blob/3860416c134ee576a5240ce053af71ea814fa56a/src/Datatables.php#L145-L151

so you can try :


    $datatables = new Datatables( $db_adapter );

    $datatables->query('YOUR SQL QUERY');

    echo $datatables->getColumns(); // will give you column names