本文整理汇总了PHP中REST::preferred方法的典型用法代码示例。如果您正苦于以下问题:PHP REST::preferred方法的具体用法?PHP REST::preferred怎么用?PHP REST::preferred使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类REST
的用法示例。
在下文中一共展示了REST::preferred方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: success
function success($message = "success", $status = false)
{
if ($status) {
REST::response_code($status);
} elseif (REST::response_code() >= 300) {
REST::response_code(200);
}
if (REST::preferred("text/html")) {
echo '<div class="container"><div class="alert alert-success">' . $message . '</div></div>';
} else {
echo $message;
}
}
示例2: fetch
}
// POST //
$id = fetch("SELECT MAX(RID)+1 as id FROM reports")[0]["id"];
if (!$id) {
$id = 1;
}
$content = file_get_contents("php://input");
global $db;
$q = $db->prepare("INSERT INTO reports (RID, DID, Content) VALUES (:report_id, :device_id, :content)");
if (!$q->execute(array(":report_id" => $id, ":device_id" => $device_id, ":content" => $content))) {
return error("failure", "Failed to post the report.");
}
// REPLY / RENDER //
REST::response_code("created");
header('Location: ' . lnk("/reports/{$id}"));
if (!REST::preferred("text/html")) {
return success("Successfully posted the report.");
} else {
echo '<script type="text/javascript">window.location.href="' . lnk("/reports/{$id}") . '"</script>"';
}
} else {
return error("bad-method", "Unsupported HTTP Method");
}
}
handle_item_commands:
if (count(REST::$ARGS) == 3 && REST::$ARGS[2] == "commands") {
if (REST::$REQUEST_METHOD == "GET") {
$device_id = REST::$ARGS[1];
if (isset($_REQUEST["since"])) {
$since = $_REQUEST["since"];
} else {