Нужно передать параметры запроса, этих параметров может быть несколько (в зависимости сколько выбрал пользователь), там например нужно искать по такой-то стране, по такой то дате, по такому то формату и так дальше, ну и в итоге вывести результат. Проблема в том что не могу передать параметры с front-end к back-end..Использую AngularJS и slim framework.
Пример кода на php
$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;
});
и пример кода 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');
});
};
});