本文整理汇总了PHP中Option::getObjects方法的典型用法代码示例。如果您正苦于以下问题:PHP Option::getObjects方法的具体用法?PHP Option::getObjects怎么用?PHP Option::getObjects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Option
的用法示例。
在下文中一共展示了Option::getObjects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
// =========================================================================
// Register the monolog logging service
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => 'php://stderr'));
// Register view rendering
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
// Register patch and delete http methods
use Symfony\Component\HttpFoundation\Request;
Request::enableHttpMethodParameterOverride();
$app->get('/', function () use($app) {
return $app['twig']->render('index.html.twig');
#, array('options' => Option::getAll()));
});
$app->post('/options', function () use($app) {
$suitable_option_names = $_POST["option_names"];
$suitable_option_ids = Option::getIdsFromNames($suitable_option_names);
$options = Option::getObjects($suitable_option_ids);
$suitable_restaurants = Restaurant::suitableRestaurants($suitable_option_ids);
return $app['twig']->render('results.html.twig', array('suitable_restaurants' => $suitable_restaurants, 'options' => $options));
});
$app->get('/admin', function () use($app) {
return $app['twig']->render('admin.html.twig', array('restaurants' => Restaurant::getAll(), 'options' => Option::getAll()));
});
$app->post('/add_restaurants', function () use($app) {
$restaurant_name = new Restaurant($_POST['restaurant_name']);
$restaurant_name->save();
return $app['twig']->render('admin.html.twig', array('restaurants' => Restaurant::getAll(), 'options' => Option::getAll()));
});
$app->post('/add_options', function () use($app) {
$option_name = new Option($_POST['option_name']);
$option_name->save();
return $app['twig']->render('admin.html.twig', array('restaurants' => Restaurant::getAll(), 'options' => Option::getAll()));
示例2: test_getObjects
function test_getObjects()
{
//arrange
$name = "Peanut-free";
$test_allergy = new Option($name);
$test_allergy->save();
$name2 = "Gluten-free";
$test_allergy2 = new Option($name2);
$test_allergy2->save();
//act
$option_ids = array();
array_push($option_ids, $test_allergy->getId(), $test_allergy2->getId());
$result = Option::getObjects($option_ids);
//assert
$this->assertEquals([$test_allergy, $test_allergy2], $result);
}