-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.php
52 lines (44 loc) · 1.95 KB
/
app.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require_once __DIR__."/../vendor/autoload.php";
require_once __DIR__."/../src/Car.php";
$app['debug']=true;
session_start();
if(empty($_SESSION['list_of_cars'])) {
$porsche = new Car("2014 Porsche 911", 114991, 7864, "/img/911.jpg");
$ford = new Car("2011 Ford F450", 55995, 14241, "img/f450.jpeg");
$lexus = new Car("2013 Lexus RX 350", 44700, 20000, "img/rx350.jpg");
$mercedes = new Car("Mercedes Benz CLS550", 39900, 37979, "img/cls550.jpeg");
$_SESSION['list_of_cars'] = array($porsche, $ford, $lexus, $mercedes);
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path'=> __DIR__.'/../views'));
$app->get('/', function() use ($app) {
// $_SESSION['list_of_cars'] = array();
$cars = $_SESSION['list_of_cars'];
return $app['twig']->render('index.html.twig', array('cars'=> $cars));
});
$app->get('/new_car', function() use ($app) {
return $app['twig']->render('new_car.html.twig');
});
$app->post('/boing', function() use ($app) {
$car_list = new Car ($_POST['make'], $_POST['price'], $_POST['mileage'], $_POST['image']);
$car_list->saveCar();
$cars = $_SESSION['list_of_cars'];
return $app['twig']->render('index.html.twig', array('cars'=> $cars));
});
$app->get('/sort_cars', function() use ($app) {
return $app['twig']->render('car_sort.html.twig');
});
$app->post('/sorter', function() use ($app) {
$cars = $_SESSION['list_of_cars'];
$cars_matching_search = array();
foreach ($cars as $car) {
if ($car->worthBuying($_POST['priceInput'], $_POST['mileageInput'])) {
array_push($cars_matching_search, $car);
}
}
// *something*::filterCars($cars)
return $app['twig']->render('index.html.twig', array('cars' => $cars_matching_search));
});
return $app;
?>