本文整理汇总了PHP中Car::worthBuying方法的典型用法代码示例。如果您正苦于以下问题:PHP Car::worthBuying方法的具体用法?PHP Car::worthBuying怎么用?PHP Car::worthBuying使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car::worthBuying方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
$app['debug'] = true;
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
session_start();
if (empty($_SESSION['list_of_cars'])) {
$porsche = new Car("2014 Porsche 911", 114991, 7864, "images/porsche.jpg");
$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");
$cars = array($porsche, $ford, $lexus, $mercedes);
$_SESSION['list_of_cars'] = $cars;
}
$app->get("/", function () use($app) {
$cars = $_SESSION['list_of_cars'];
return $app['twig']->render('cars.html.twig', array('cars' => $cars));
});
$app->post("/create_cars", function () use($app) {
$car = new Car($_POST['make'], $_POST['miles'], $_POST['price'], $_POST['image']);
$car->save();
return $app['twig']->render('create_cars.html.twig', array('car' => $car));
});
$app->post("/search_car", function () use($app) {
$cars_matching_search = array();
foreach ($_SESSION['list_of_cars'] as $car) {
if ($car->worthBuying($_POST["price"], $_POST["miles"])) {
array_push($cars_matching_search, $car);
}
}
return $app['twig']->render('search_car.html.twig', array('cars_matching_search' => $cars_matching_search));
});
return $app;
示例2: array
$_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;