} } //Determining whether the field is Name, Prep Time, Total Time, and Rating if (isset($_GET['field'])) { if ($_GET['field'] == 'Name') { $fieldName = "Name"; } else { if ($_GET['field'] == 'Prep') { $fieldName = "Prep"; } else { if ($_GET['field'] == 'Total') { $fieldName = "Total"; } else { if ($_GET['field'] == 'Rating') { $fieldName = "Rating"; } } } } } // get form data (part 3) //If user clicks button, this happens if ($_POST) { $searching = $_POST["terms"]; $recipes = Recipe::findByKeyword($dbh, $searching, true); require_once "views/view_recipes.php"; } else { $recipes = Recipe::findAll($dbh, $sortingTitle, $fieldName, true); // require the view require_once "views/view_recipes.php"; }
<?php // a simple test controller for your lab work // we're not going to bother with a view // db connection require_once "models/DB.php"; require_once "models/Recipe.php"; require_once "models/RecipeStep.php"; $id = 1; // inflate recipe object $recipes = Recipe::findAll($dbh, true); // dump recipe details // dump recipe steps for ($i = 0; $i < count($recipes); $i++) { for ($j = 0; $j < count($recipes[$i]->recipe_steps); $j++) { print $recipes[$i]->recipe_steps[$j]; } } // dump recipe ingredients/units names for ($i = 0; $i < count($recipes); $i++) { for ($j = 0; $j < count($recipes[$i]->recipe_details); $j++) { print $recipes[$i]->recipe_details[$j]; } }
require_once "models/Recipe.php"; require_once "models/db.php"; $recipes = new Recipe(); $new_recepies = new Recipe(); $order = 0; // Keeps track of the asc, desc order. // using the Recipe model, retrieve an array of recipes $recipes = Recipe::findAll($dbh); // get querystring data (part 2) if ($_GET) { if (array_key_exists('sort', $_GET)) { // Explode the value and get the name of the column to be sorted, and the $order it should sort it. $arr = explode('_', $_GET['sort']); $column = $arr[0]; $order = $arr[1]; $recipes = Recipe::findAll($dbh, $column, $order); if ($order == 0) { $order = 1; } else { $order = 0; } } } // get form data (part 3) if ($_POST) { // Get the string from $_POST, and search for that string in the database. if (array_key_exists("terms", $_POST)) { $keyWord = $_POST["terms"]; $recipes = Recipe::findByKeyword($dbh, $keyWord); } }
<?php // include models, including the database connection require_once "models/DB.php"; require_once "models/Recipe.php"; require_once "models/Ingredient.php"; require_once "models/units_of_measure.php"; // get querystring data (part 2) $recipe = Recipe::findAll($dbh); $newRecipe; if (isset($_GET['Details'])) { $viewID = $_GET['Details']; require_once "ShowRecipe.php"; $newRecipe = 0; die; } else { if (isset($_GET['order'])) { $recipe = Recipe::sortBy($dbh, $_GET['order']); } else { if (isset($_GET['addRecipe'])) { //$ing = Ingredient::sortIngredientASC($dbh); //$units = units_of_measure::sortUnitsASC($dbh); $ing = Ingredient::findAll($dbh); $units = units_of_measure::findAll($dbh); $newRecipe = 1; require_once "EditRecipe.php"; die; } } } if ($_POST) {