本文整理汇总了PHP中REST::response_code方法的典型用法代码示例。如果您正苦于以下问题:PHP REST::response_code方法的具体用法?PHP REST::response_code怎么用?PHP REST::response_code使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类REST
的用法示例。
在下文中一共展示了REST::response_code方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: error
if (!$auth_info || !isset($auth_info[0])) {
return error(401, "Unauthorized!");
}
// 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"])) {
示例3: elseif
}
echo "Device ID:\t" . $device["id"] . "\n";
echo "Name:\t" . $device["name"] . "\n";
echo "Address:\t" . $device["address"] . "\n";
echo "Last heard:\t" . $device["lastheard"] . "\n";
echo "Reports:\t" . $device["reportcount"] . "\n";
} elseif (!REST::preferred("text/html")) {
if (!$device) {
REST::response_code("not-found");
echo "NULL";
return;
}
echo json_encode($device);
} else {
if (!$device) {
REST::response_code("not-found");
?>
<?php
echo_breadcrumbs_bar(array(lnk("/devices") => "Devices", "Not found"));
?>
<div class="main">
<div class="container">
<div class="title">
Sorry, the device was not found!
</div>
</div>
</div>
<?php
示例4: error
<?php
global $devices;
if (!isset($devices)) {
return error(500, "Illegal state!");
}
if (count($devices) == 0) {
REST::response_code("empty");
}
// Plain text representation //
if (!REST::preferred("text/html") && !REST::preferred("application/json")) {
foreach ($devices as $device) {
echo "(" . $device["id"] . ") " . $device["name"] . "\n";
}
// JSON representation //
} elseif (!REST::preferred("text/html")) {
foreach ($devices as &$device) {
$device["link"] = lnk("/devices/" . $device["id"]);
unset($device["address"]);
}
echo json_encode($devices);
// HTML representation //
} else {
?>
<div class="main">
<div class="container">
<div class="title">Registered devices:</div>
<ul class="device-list">
<?php