本文整理匯總了PHP中ItemManager::GetById方法的典型用法代碼示例。如果您正苦於以下問題:PHP ItemManager::GetById方法的具體用法?PHP ItemManager::GetById怎麽用?PHP ItemManager::GetById使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ItemManager
的用法示例。
在下文中一共展示了ItemManager::GetById方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: hash
<?php
include_once "ItemManager.php";
$SALT = "skatingatonementshark";
$method = $_SERVER['REQUEST_METHOD'];
$ip = $_SERVER['REMOTE_ADDR'];
$toHash = $ip . $SALT;
$expectedToken = hash('sha256', $toHash);
$token = $_SERVER['HTTP_TOKEN'];
if ($token === $expectedToken) {
switch ($method) {
case "GET":
if (isset($_GET['id']) && !empty($_GET['id'])) {
//getting record by id
$id = $_GET['id'];
$item = ItemManager::GetById($id);
echo json_encode($item);
} else {
//getting all records
$items = ItemManager::GetAllItems();
echo json_encode($items);
}
break;
case "PUT":
$newRecordData = fopen("php://input", "r");
$data = stream_get_contents($newRecordData);
fclose($newRecordData);
parse_str($data);
$newId = ItemManager::AddNewItem($desc, $price, $quantity);
echo "The item {$desc} has been inserted with the id {$newId}.";
break;