/** * @param $query - The search query used to find restaurants */ public function search($query) { $results = Restaurant::search($query); echo json_encode($results); }
$restaurant->save(); $cuisine = Cuisine::find($cuisine_id); return $app['twig']->render('cuisine.html.twig', array('cuisine' => $cuisine, 'restaurants' => $cuisine->getRestaurants())); }); //Reviews page $app->get("/restaurants/{id}", function ($id) use($app) { $restaurant = Restaurant::find($id); return $app['twig']->render('restaurant.html.twig', array('restaurant' => $restaurant, 'reviews' => $restaurant->getReviews())); }); $app->post("/reviews", function () use($app) { $username = $_POST['username']; $date = $_POST['date']; $rating = $_POST['rating']; $comment = $_POST['comment']; $restaurant_id = $_POST['restaurant_id']; $review = new Review($username, $date, $rating, $comment, $restaurant_id, $id = null); $review->save(); $restaurant = Restaurant::find($restaurant_id); return $app['twig']->render('restaurant.html.twig', array('restaurant' => $restaurant, 'reviews' => Review::getAll())); }); //Cuisine_edit page $app->get("/cuisines/{id}/edit", function ($id) use($app) { $cuisine = Cuisine::find($id); return $app['twig']->render('cuisine_edit.html.twig', array('cuisine' => $cuisine)); }); //Search result page $app->get("/search", function () use($app) { $search = Restaurant::search($_GET['search']); return $app['twig']->render('search.html.twig', array('search' => $search, 'search_term' => $_GET['search'])); }); return $app;
<body> <?php include "./include/navbar.php"; ?> <div class="container" style="margin-top:100px;margin-bottom:50px;min-height:500px"> <?php if (isset($_POST['location'])) { ?> <h1>Search: <?php echo $_POST['location']; ?> </h1> <div class="col-sm-8"> <?php $restaurant = new Restaurant(); $data = $restaurant->search($_POST['location']); if (sizeof($data) > 0) { foreach ($data as $key => $value) { echo '<div class="row" restaurant-id="' . $value['id'] . '"> <div class="col-sm-2"> <a href="/restaurants.php?id=' . $value['id'] . '"><img src=".' . $value['image'] . '" height="90px" width="90px"></a> </div> <div class="col-sm-6"> <a href="/restaurants.php?id=' . $value['id'] . '"><h4>' . ($key + 1) . '. ' . $value['name'] . '</h4></a> <h4>' . $value['rating'] . ' star rating ' . $value['review_count'] . ' reviews</h4> </div> <div class="col-sm-4"> <h5>' . $value['address1'] . '</h5> <h5>' . $value['address2'] . '</h5> <h5>' . $value['phone'] . '</h5> </div>