本文整理汇总了PHP中Place::getAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Place::getAll方法的具体用法?PHP Place::getAll怎么用?PHP Place::getAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Place
的用法示例。
在下文中一共展示了Place::getAll方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: session_start
<?php
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Place.php";
session_start();
if (empty($_SESSION['list_of_places'])) {
$_SESSION['list_of_places'] = 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('places.html.twig', array('places' => Place::getAll()));
});
$app->post("/places", function () use($app) {
$place = new Place($_POST['city']);
$place->save();
return $app['twig']->render('create_place.html.twig', array('newplace' => $task));
});
return $app;
示例2: function
// routes
$app->get("/", function () use($app) {
return $app['twig']->render('home.html.twig', array('places' => Place::getAll()));
});
$app->post('/add_place', function () use($app) {
$place = new Place($_POST['city'], $_POST['country'], $_POST['year'], $_POST['image_src']);
$place->save();
return $app['twig']->render('home.html.twig', array('places' => Place::getAll(), 'message' => array("text" => "Sounds like a fun trip!", 'type' => 'info')));
});
$app->post('/delete_all', function () use($app) {
Place::deleteAll();
return $app['twig']->render('home.html.twig', array('places' => Place::getAll(), 'message' => array("text" => "Time to book a trip!", 'type' => 'info')));
});
$app->post('/delete_one', function () use($app) {
$name_of_place = $_POST['delete_one'];
$found = false;
foreach ($_SESSION['list_of_places'] as $key => $place) {
if ($place->getCity() == $name_of_place) {
$found = true;
$key_to_delete = $key;
break;
}
}
$place_to_delete = $_SESSION['list_of_places'][$key];
$place_to_delete->delete();
return $app['twig']->render('home.html.twig', array('places' => Place::getAll(), 'message' => array("text" => $name_of_place . " was deleted!", 'type' => 'danger')));
});
$app->get('/show_form', function () use($app) {
return $app['twig']->render('home.html.twig', array('places' => Place::getAll(), 'form' => true));
});
return $app;
示例3: session_start
<?php
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Place.php";
//SESSION - Stores Cookies
session_start();
if (empty($_SESSION['list_of_cities'])) {
$_SESSION['list_of_cities'] = array();
}
$app = new Silex\Application();
//Twig Path
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
//Route and Controller
$app->get("/", function () use($app) {
$all_cities = Place::getAll();
return $app['twig']->render('city.html.twig', array('cities' => $all_cities));
});
/* $app->get("/", function() use ($app) {
$all_times = Place::getAll();
return $app['twig']->render('city.html.twig', array('times' => $all_times));
}); */
//cities POST
$app->post("/city", function () use($app) {
$city = new Place($_POST['cityName'], $_POST['lengthOfTime'], $_POST['reasonOfVisit'], $_POST['imagePath']);
$city->save();
return $app['twig']->render('create_city.html.twig', array('newcity' => $city));
});
//cities POST delete
示例4: testDeleteAll
function testDeleteAll()
{
//Arrange
$place_name = "Director Park";
$address = "SW Park Ave";
$latitude = 45.518672;
$longitude = -122.681211;
$id = 1;
$test_place = new Place($place_name, $address, $latitude, $longitude, $id);
$test_place->save();
//Act
Place::deleteAll();
$result = Place::getAll();
//Assert
$this->assertEquals([], $result);
}
示例5: generateLocation
static function generateLocation()
{
$places = Place::getAll();
$number_of_places = count($places);
$random_number = rand(0, $number_of_places - 1);
$random_location = $places[$random_number];
return $random_location;
}