本文整理汇总了PHP中Food::setFoodTypeId方法的典型用法代码示例。如果您正苦于以下问题:PHP Food::setFoodTypeId方法的具体用法?PHP Food::setFoodTypeId怎么用?PHP Food::setFoodTypeId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Food
的用法示例。
在下文中一共展示了Food::setFoodTypeId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public static function create()
{
$foodData = json_decode($_POST["foodData"], true);
$result = array();
$validate = true;
$result["foodName"] = false;
$result["foodPrice"] = false;
$result["foodType"] = false;
if (!isset($foodData["foodName"]) || empty($foodData["foodName"])) {
$result['foodName'] = true;
$validate = false;
}
if (!isset($foodData["foodPrice"]) || empty($foodData["foodPrice"])) {
$result['foodPrice'] = true;
$validate = false;
}
if (!isset($foodData["foodType"]) || empty($foodData["foodType"])) {
$result['foodType'] = true;
$validate = false;
}
if (!isset($foodData["image"]) || empty($foodData["image"])) {
$result['image'] = true;
$validate = false;
}
if ($validate == false) {
echo json_encode($result);
return;
}
$x = $y = 0;
$s = 250;
$d = 100;
$sizer = new ImageSizer();
$sizer->load(self::$tmpDir . $foodData["image"]);
$width = $sizer->getWidth();
$height = $sizer->getHeight();
$sizer->save(self::$imageDir . $foodData["image"]);
$x = $width * ($foodData["cropX"] / $foodData["imageW"]);
//echo $width." ".$foodData["cropX"]." ".$x."<br>";
$y = $height * ($foodData["cropY"] / $foodData["imageH"]);
//echo $height." ".$foodData["cropY"]." ".$y."<br>";
$d = $width * ($foodData["cropW"] / $foodData["imageW"]);
//echo $foodData["cropW"]." ".$d;
if (intval($d) != 0) {
$sizer->resize($x, $y, $s, $d);
$sizer->save(self::$thumDir . $foodData["image"]);
}
$food = new Food();
$food->setName($foodData["foodName"]);
$food->setPrice($foodData["foodPrice"]);
$food->setFoodTypeId(1);
$food->setStatus(true);
$food->setThumbnail($foodData["image"]);
$food->setImage($foodData["image"]);
$food->insertDatabase(null);
echo json_encode($result);
}