コード例 #1
0
$ford = new Car("2011 Ford F450", 55995, 14241, "images/ford.jpg");
$lexus = new Car("2013 Lexus RX 350", 44700, 20000, "images/lexus.jpg");
$mercedes = new Car("Mercedes Benz CLS550", 39900, 37979, "images/mercedes.jpg");
if (empty($_SESSION['list_of_cars'])) {
    $_SESSION['list_of_cars'] = array($porsche, $ford, $lexus, $mercedes);
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
/* CAR_FORM.HTML.TWIG - Home route */
$app->get("/", function () use($app) {
    return $app['twig']->render('car_form.html.twig', array('cars' => Car::getAll()));
});
/* END CAR_FORM.HTML.TWIG */
/* START VIEW_CAR.HTML.TWIG */
$app->get("/view_car", function () use($app) {
    $cars = Car::getAll();
    $cars_matching_search = array();
    foreach ($cars as $car) {
        if ($car->worthBuying($_GET["price"]) && $car->worthBuying($_GET["miles"])) {
            array_push($cars_matching_search, $car);
        }
    }
    return $app['twig']->render('view_car.html.twig', array('cars' => $cars_matching_search));
});
/* END VIEW_CAR.HTML.TWIG */
/* BEGIN SELL_CAR.HTML.TWIG */
$app->get("/sell_car", function () use($app) {
    return $app['twig']->render('sell_car.html.twig');
});
$app->post("/car_added", function () use($app) {
    $car = new Car($_POST['make'], $_POST['price'], $_POST['miles'], $_POST['photo']);
コード例 #2
0
ファイル: app.php プロジェクト: kellimargaret/Car-Dealership
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
// $app['debug'] = true;
// Home Page - Search
$app->get("/", function () use($app) {
    return $app['twig']->render('cars.html.twig');
});
// Home Page - Results/Post
$app->post("/New_Car", function () use($app) {
    $car = new Car($_POST['make_model'], $_POST['price'], $_POST['miles'], $_POST['picture']);
    $car->save();
    return $app['twig']->render('New_Car.html.twig', array('newcar' => $car));
});
// Your Cars - Results Page
$app->get('/your_cars', function () use($app) {
    var_dump(Car::getAll());
    return $app['twig']->render('your_cars.html.twig', array('cars' => Car::getAll()));
});
/* Create objects for the Car class, and store the worth buying array while
   routing the results to cars_matching_search.html.twig */
$app->get("/car_results", function () use($app) {
    $first_car = new Car("2014 Porsche 911", 7864, 114991, "images/porsche.jpg");
    $second_car = new Car("2011 Ford F450", 14000, 55995, "images/ford.jpeg");
    $third_car = new Car("2013 Lexus RX 350", 20000, 44700, "images/lexus.jpg");
    $fourth_car = new Car("Mercedes Benz CLS550", 37979, 39900, "images/mercedes.jpg");
    $cars = array($first_car, $second_car, $third_car, $fourth_car);
    $cars_matching_search = array();
    foreach ($cars as $car) {
        if ($car->worthBuying($_GET["price"], $_GET["miles"])) {
            array_push($cars_matching_search, $car);
        }
    }
コード例 #3
0
 public function testHelperMethods()
 {
     $cars = Car::getAll();
     $this->assertEquals('cars', Car::getTablename());
     $this->assertEquals('id', Car::getUniqueId());
 }
コード例 #4
0
ファイル: app.php プロジェクト: adamrr724/Car-PHP
    $_SESSION['cars_list'] = array();
}
$app = new Silex\Application();
// $app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('car_form.html.twig');
});
$app->post("/show", function () use($app) {
    $car = new Car($_POST['model'], $_POST['price'], $_POST['image'], $_POST['miles']);
    $car->save();
    return $app['twig']->render('car_dealership.html.twig', array('cars' => Car::getAll()));
});
$app->get("/list", function () use($app) {
    return $app['twig']->render('car_dealership.html.twig', array('cars' => Car::getAll()));
});
$app->get("car_search", function () use($app) {
    $cars = Car::getAll();
    $cars_matching_search = array();
    foreach ($cars as $car) {
        if ($car->worthBuying($_GET["price"]) && $car->maxMileage($_GET["mileage"])) {
            array_push($cars_matching_search, $car);
        }
    }
    return $app['twig']->render('car_search.html.twig', array('cars' => $cars_matching_search));
});
$app->post("/clear", function () use($app) {
    Car::reset();
    return $app['twig']->render('car_dealership.html.twig', array('cars' => Car::getAll()));
});
return $app;
コード例 #5
0
ファイル: app.php プロジェクト: alexMcosta/cars_2.0
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
//Route and Controller
$app->get('/', function () use($app) {
    $all_cars = Car::getAll();
    return $app['twig']->render('cars.html.twig', array('cars' => $all_cars));
});
//Cars Post
$app->post('/cars', function () use($app) {
    $car = new Car($_POST['carModel'], $_POST['carPrice'], $_POST['carMiles'], $_POST['carPhoto']);
    $car->save();
    return $app['twig']->render('create_cars.html.twig', array('newcar' => $car));
});
//Cars Post Delete
$app->post("/delete_cars", function () use($app) {
    Car::deleteAll();
    return $app['twig']->render('delete_cars.html.twig');
});
//car search
$app->get("/car_results", function () use($app) {
    $search = Car::getAll();
    $cars_matching_search = array();
    foreach ($search as $result) {
        if ($result->getPrice() < $_GET["price"]) {
            if ($result->getMiles() < $_GET["miles"]) {
                array_push($cars_matching_search, $result);
            }
        }
    }
    return $app['twig']->render('car_results.html.twig', array('search_data' => $cars_matching_search));
});
return $app;
コード例 #6
0
ファイル: app.php プロジェクト: jcfix/car-dealership
<?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;
コード例 #7
0
ファイル: app.php プロジェクト: blakerscott/dealership-twig
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/car.php";
session_start();
if (empty($_SESSION['list_of_cars'])) {
    $_SESSION['list_of_cars'] = array();
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app['debug'] = true;
$app->get("/", function () use($app) {
    return $app['twig']->render('home.html.twig', array('cars' => Car::getAll()));
});
$app->get("/car_output", function () use($app) {
    $cars_matching_search = array();
    foreach (Car::getAll() as $car) {
        if ($car->worthBuying($_GET["price"], $_GET["mileage"])) {
            array_push($cars_matching_search, $car);
        }
    }
    return $app['twig']->render('caroutput.html.twig', array('cars' => $cars_matching_search));
});
$app->get("/newlisting", function () use($app) {
    return $app['twig']->render('newlisting.html.twig');
});
$app->post("/listingresult", function () use($app) {
    $car = new Car($_POST['make_model'], $_POST['price'], $_POST['mileage']);
    $cars_listed = array($car);
    $car->save();
    return $app['twig']->render('listingresult.html.twig', array('newcars' => $cars_listed));
});
コード例 #8
0
ファイル: app.php プロジェクト: juliocesardiaz/Dealership
    $firstCar = new Car("Tesla X", 100000, 0, "pictures/tesla.jpg");
    $secondCar = new Car("Honda Accord", 10000, 50000, "pictures/honda.jpg");
    $thirdCar = new Car("Ferrari Enzo", 350000, 15000, "pictures/ferrari-enzo.jpg");
    $fourthCar = new Car("Toyota Corolla", 6000, 100000, "pictures/toyota-corolla.jpg");
    $fifthCar = new Car("Mitsubishi Lancer", 20000, 100, "pictures/mitsubishi-lancer.jpg");
    $allCars = array($firstCar, $secondCar, $thirdCar, $fourthCar, $fifthCar);
    $_SESSION['list_of_cars'] = $allCars;
}
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('dealership_search.html.twig');
});
$app->get("/view_cars", function () use($app) {
    $totalCars = Car::getAll();
    $matchingCars = array();
    $max_price = $_GET["max_price"];
    $max_miles = $_GET["max_mileage"];
    foreach ($totalCars as $car) {
        $price = $car->getPrice();
        $mileage = $car->getMiles();
        if ($price <= $max_price && $mileage <= $max_miles) {
            array_push($matchingCars, $car);
        }
    }
    return $app['twig']->render('results.html.twig', array('matchedCars' => $matchingCars));
});
$app->get("/car_form", function () use($app) {
    return $app['twig']->render('car_form.html.twig');
});