コード例 #1
0
<?php

require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'trest_init.php');
require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'Sandwich.php');
require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'Ingredient.php');
header('Content-Type: application/json');
$id = @$_GET['id'];
$id = (int) $id;
if ($id) {
    $result = Ingredient::find($id);
} else {
    $result = Ingredient::findAll();
}
echo json_encode($result);
コード例 #2
0
 /**
  * Retrieves all ingredients from the database and displays them.
  */
 public static function get_ingredients()
 {
     $ingredients = Ingredient::findAll();
     View::make('ingredient/list.html', array('ingredients' => $ingredients));
 }
コード例 #3
0
ファイル: EditRecipe.php プロジェクト: xavidram/RecipeListPHP
$editRecipe;
if (isset($_GET['addRecipe'])) {
    //new recipe
    $editRecipe = 0;
    require_once "views/edit_recipe.php";
    die;
} else {
    if (isset($_GET['edit'])) {
        require_once "models/DB.php";
        require_once "models/Recipe.php";
        require_once "models/Ingredient.php";
        require_once "models/units_of_measure.php";
        require_once "models/Step.php";
        //pull ingredients and units of measure alphabetically from database
        $ing = Ingredient::findAll($dbh);
        $units = units_of_measure::findAll($dbh);
        $newEntry = new Recipe();
        $newEntry->find($_GET['edit'], $dbh);
        $steps = Step::findAllSteps($dbh, $_GET['edit']);
        $ingredients = Ingredient::findAllIngredients($dbh, $_GET['edit']);
        $editRecipe = 1;
        require_once "views/edit_recipe.php";
        die;
    }
}
// Route 1: user comes here to add a new recipe, show them a blank form
// Route 2: user comes here to edit a specific recipe
//   (you'll need to grab that id from the query string)
// Route 3a: user entered a new recipe details and is trying to save it
//   create an object, set values, validate and save, just like in the lab
コード例 #4
0
function GetIngredients()
{
    require_once "models/Ingredient.php";
    $ingredients = Ingredient::findAll($dbh, true);
    return json_encode($ingredients);
}