phputil / datatables
Datatables 请求和响应的 PHP 表示。
2.0.1
2017-01-09 18:37 UTC
Requires
- php: >=5.4
- phputil/traits: >=1.3
Requires (Dev)
- phpunit/phpunit: =4.4.2
This package is auto-updated.
Last update: 2024-09-23 04:07:07 UTC
README
Datatables 的请求和响应的 PHP 表示。Datatables
主要文件
安装
composer require phputil/datatables
版本 2.x
的示例
<?php require_once 'vendor/autoload.php'; use phputil\datatables\DataTablesRequest; use phputil\datatables\DataTablesResponse; // // REQUEST // $req = new DataTablesRequest( $_POST ); // PAGINATION $offset = $req->start; $limit = $req->length; // SEARCH $searchValue = $req->searchValue(); // Example: 'Alice' // FILTERING $search = $req->columnSearch(); // Example: array( 'name' => 'Bob', 'age' => 21 ) // SORTING $order = $req->columnOrder(); // Example: array( 'name' => 'ASC', 'age' => 'DESC' ) ... // // RESPONSE // $totalCount = /* total number of records to return */ $filteredCount = /* filtered number of records to return */ $data = /* items to return */ $draw = $req->draw; // From the request $res = new DataTablesResponse( $totalCount, $filteredCount, $data, $draw ); echo json_encode( $res ); ?>
版本 1.x
的示例
<?php require_once 'vendor/autoload.php'; use phputil\DataTablesRequest; use phputil\DataTablesResponse; // // REQUEST // $req = new DataTablesRequest( $_POST ); // PAGINATION $limit = $req->limit(); $offset = $req->offset(); // SEARCH $search = $req->search(); // null in case of not having search // FILTERING $filters = $req->filters(); // Example: array( 'name' => 'Bob', 'age' => 21 ) // SORTING // Originally, Datatables returns the sort order // by column index, but here you can get it using // your own column names. $orders = $req->orders( array( 'name', 'age' ) ); // Example: array( 'name' => 'asc', 'age' => 'desc' ) ... // // RESPONSE // $totalCount = /* total number of records to return */ $filteredCount = /* filtered number of records to return */ $data = /* items to return */ $draw = $req->draw(); // From the request $res = new DataTablesResponse( $totalCount, $filteredCount, $data, $draw ); echo json_encode( $res ); ?>