Esempio n. 1
0
File: app.php Progetto: jmalo34/car
    //in order to get the default value to be applied, i had to remove "$POST['miles']" entirely. so, it seems as if there's nothing to detect whether it is a value of zero or not, and what to do if that is not okay. check
    $new_car->save();
    echo "<pre>";
    print_r($new_car);
    echo "</pre><br>";
    return $app['twig']->render('list_car.html.twig', array('list_car' => $new_car));
});
$app->get("/car_lot", function () use($app) {
    return $app['twig']->render('car_lot.html.twig', array('autos' => Car::getAll()));
});
$app->get("/match_cars", function () use($app) {
    $cars = Car::getAll();
    $cars_matching_search = array();
    foreach ($cars as $car) {
        if ($car->worthBuying($_GET['max_price'], $_GET['max_miles'])) {
            array_push($cars_matching_search, $car);
        }
    }
    echo "<pre>";
    print_r($cars);
    echo "</pre><br>";
    echo "<pre>";
    print_r($cars_matching_search);
    echo "</pre><br>";
    return $app['twig']->render('match_cars.html.twig', array('cars_matching_search' => $cars_matching_search));
});
$app->post("/delete_cars", function () use($app) {
    Car::deleteAll();
    return $app['twig']->render('delete_cars.html.twig');
});
return $app;
Esempio n. 2
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Car.php";
session_start();
if (empty($_SESSION['car_list'])) {
    $_SESSION['car_list'] = array();
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('add_car.html.twig');
});
$app->post("/confirmation", function () use($app) {
    $car = new Car($_POST['make_model'], $_POST['price'], $_POST['miles']);
    $car->save();
    return $app['twig']->render('confirmation.html.twig', array('newcar' => $car));
});
$app->get("/car_list", function () use($app) {
    return $app['twig']->render('car_list.html.twig', array('cars' => Car::getAll()));
});
$app->get("/search_results", function () use($app) {
    return $app['twig']->render('search_results.html.twig', array('cars' => Car::getAll(), 'max_price' => $_GET['price']));
});
$app->post("/clear_list", function () use($app) {
    return $app['twig']->render('car_list.html.twig', array('cars' => Car::deleteAll()));
});
return $app;