require 'sql.php'; require 'model/Pokemon.php'; require 'model/Trainer.php'; require 'model/Gym.php'; require 'model/Type.php'; require 'model/Badge.php'; ini_set("display_errors", 'On'); error_reporting(E_ALL); $app = new \Slim\Slim(); function sendResponse($data) { echo json_encode($data, JSON_PRETTY_PRINT); } $app->get("/search/:str", function ($searchStr) use($app) { $objects = array(); $objects["badges"] = Badge::search($searchStr); $objects["gyms"] = Gym::search($searchStr); $objects["pokemon"] = Pokemon::search($searchStr); $objects["trainers"] = Trainer::search($searchStr); $objects["types"] = Type::search($searchStr); foreach ($objects["types"] as $type) { $typeId = intval($type["id"]); $pokemonForType = Pokemon::searchByType($typeId); foreach ($pokemonForType as $pokemon) { if (!in_array($pokemon, $objects["pokemon"])) { array_push($objects["pokemon"], $pokemon); } } } sendResponse($objects); });