当前位置: 首页>>代码示例>>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;未经允许,请勿转载。