本文整理汇总了PHP中Recipe::getIngredients方法的典型用法代码示例。如果您正苦于以下问题:PHP Recipe::getIngredients方法的具体用法?PHP Recipe::getIngredients怎么用?PHP Recipe::getIngredients使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Recipe
的用法示例。
在下文中一共展示了Recipe::getIngredients方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRecipeWhenValid
public function testRecipeWhenValid()
{
$name = 'bread with butter';
$ingredients = array(new Ingredient('bread', 1, 'slices', new DateTime('+30 day')), new Ingredient('butter', 1, 'slices', new DateTime('+15 day')));
$recipe = new Recipe($name, $ingredients);
$this->assertEquals($recipe->getName(), $name);
$this->assertEquals($recipe->getIngredients(), $ingredients);
$this->assertEquals($recipe->getEarliestUsedBy(), new DateTime('+15 day'));
}
示例2: update_recipe
public function update_recipe()
{
$flash_string = '';
if (Session::exists('account')) {
$flash_string = Session::flash('account');
}
$user = new User();
if ($user->isLoggedIn()) {
if (Input::exists()) {
//First Validate the recipe data sent
//Update recipe data
Recipe::updateFields(Input::get('recipe_id'), ['yeild' => Input::get('recipe_yeild'), 'yeildUnit' => Input::get('recipe_unit'), 'method' => filter_var(Input::get('recipe_method'), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_ENCODE_HIGH), 'recipeName' => Input::get('recipe_name'), 'recipeCost' => Input::get('recipe_cost')]);
//foreach ingredient
$currentIds = array_column(Recipe::getIngredients(Input::get('recipe_id')), 'id');
$i = 0;
while (Input::get('id' . $i) !== '') {
$id = Input::get('id' . $i);
if (!in_array($id, $currentIds)) {
//create it
Recipe::addIngredient(Input::get('recipe_id'), $id, Input::get('quantity' . $i), Input::get('unit' . $i));
echo var_dump($currentIds);
} else {
//modify the Ingredient
Recipe::changeIngredientUnit(Input::get('recipe_id'), $id, Input::get('unit' . $i));
Recipe::changeIngredientQuantity(Input::get('recipe_id'), $id, Input::get('quantity' . $i));
//tick off $currentId from the list of $currentIds
$key = array_search($id, $currentIds);
echo 'removing from array id No.' . $currentIds[$key] . "\n";
unset($currentIds[$key]);
}
$i++;
}
//if there are any ingredients left in $currentIds then they have been deleted
echo var_dump($currentIds);
if (count($currentIds)) {
foreach ($currentIds as $id) {
echo $id . " being deleted\n";
Recipe::deleteIngredient(Input::get('recipe_id'), $id);
}
}
Session::flash('account', $error_string);
//redirect here
Redirect::to('account/recipes');
} else {
$this->view('account/recipes', ['register' => true, 'loggedIn' => 1, 'flash' => $flash_string, 'name' => $user->data()->name, 'page_name' => "", 'user_id' => $user->data()->id]);
}
} else {
Session::flash('home', 'You have been logged out, please log back in');
Redirect::to('home');
}
}