本文整理汇总了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();
示例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);
}