當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Option::getIdsFromNames方法代碼示例

本文整理匯總了PHP中Option::getIdsFromNames方法的典型用法代碼示例。如果您正苦於以下問題:PHP Option::getIdsFromNames方法的具體用法?PHP Option::getIdsFromNames怎麽用?PHP Option::getIdsFromNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Option的用法示例。


在下文中一共展示了Option::getIdsFromNames方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: PDO

$DB = new PDO($server, $username, $password);
// =========================================================================
// 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();
開發者ID:ben-pritchard,項目名稱:allergen_avoider,代碼行數:31,代碼來源:app.php

示例2: test_getIdsFromNames

 function test_getIdsFromNames()
 {
     //arrange
     $name = "peanut-free";
     $test_option = new Option($name);
     $test_option->save();
     $name2 = "soy-free";
     $test_option2 = new Option($name2);
     $test_option2->save();
     //act
     $suitable_options_names = array($test_option->getName(), $test_option2->getName());
     $result = Option::getIdsFromNames($suitable_options_names);
     //assert
     $this->assertEquals([$test_option->getId(), $test_option2->getId()], $result);
 }
開發者ID:ben-pritchard,項目名稱:allergen_avoider,代碼行數:15,代碼來源:OptionTest.php


注:本文中的Option::getIdsFromNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。