It is necessary to transfer the request parameters, there may be several of these parameters (depending on how many the user has selected), for example, you need to search for such and such a country, for such a date, for such a format, and so on, well, and finally output the result. The problem is that I can not pass the parameters from the front-end to the back-end .. I use AngularJS and slim framework.
Php code example
$app->get('/items', function (Request $request, Response $response) { // $file = 'log.txt'; $input = $request->getBody(); //file_put_contents($file,$input); $sql = 'SELECT DISTINCT items.name, items.link, items.owner, items.date_start, items.date_end, items.description, format_file.format_name FROM items, format_file WHERE items.id_format_file = format_file.id AND format_file.format_name = "' .$input['format'] . '"'; $rows = DB::fetchAll($sql); $response->getBody()->write(json_encode([ 'data' => $rows ], JSON_UNESCAPED_UNICODE)); return $response; }); and sample code js
mainApp.controller('NewsViewController', function($scope, $http) { $scope.getPosts = function(){ var paramSearch = {}; paramSearch.country = $scope.country; paramSearch.format = $scope.format; var jsonParamSearch = []; jsonParamSearch[0] = 'country'; jsonParamSearch[1] = 'format'; var jsonParam = JSON.stringify(paramSearch, jsonParamSearch, "\t"); console.log(jsonParam); $http.get('http://localhost:8088/api/rest.php/items', jsonParam).success(function(){ console.log('done'); }); }; });