本文整理汇总了PHP中Recipe::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Recipe::validate方法的具体用法?PHP Recipe::validate怎么用?PHP Recipe::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Recipe
的用法示例。
在下文中一共展示了Recipe::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Recipe
<?php
require_once "models/db.php";
require_once "models/Recipe.php";
$recipe = new Recipe();
if ($_POST) {
$recipe->copyFromRow($_POST);
if ($recipe->validate()) {
$recipe->save($dbh);
echo "save successfully";
die;
}
}
// default route, show page for adding
require_once "views/view_recipe.php";
示例2: header
$ing = Ingredient::findAll($dbh);
// Route 1: user comes here to add a new recipe, show them a blank form
$add = true;
// Route 2: user comes here to edit a specific recipe
// (you'll need to grab that id from the query string)
if (isset($_GET['id'])) {
$add = false;
$recipes->find($_GET['id'], $dbh);
}
// 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
// if all is well, send to ShowRecipe to see the added recipe
// otherwise, back to the edit view with errors!
if ($_POST && !$_GET) {
$recipes->copyFromRow($_POST);
if ($recipes->validate()) {
$recipes->save($dbh);
header('Location: RecipeList.php?id=' . $recipes->id);
}
}
// Route 3b: user updated an existing recipe details and is trying to save it
// create an object, inflate to the proper id, update values, validate and save
// if all is well, send to ShowRecipe to see the added recipe
// otherwise, back to the edit view with errors!
if ($_POST && $_GET) {
$recipes->copyFromRow($_POST);
if ($recipes->validate()) {
$recipes->save($dbh);
header('Location: RecipeList.php?id=' . $recipes->id);
}
}