当前位置: 首页>>代码示例>>PHP>>正文


PHP REST::response_code方法代码示例

本文整理汇总了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;
    }
}
开发者ID:anly2,项目名称:raspberry-spi,代码行数:13,代码来源:index.php

示例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"])) {
开发者ID:anly2,项目名称:raspberry-spi,代码行数:31,代码来源:devices.php

示例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 
开发者ID:anly2,项目名称:raspberry-spi,代码行数:31,代码来源:devices-item.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 
开发者ID:anly2,项目名称:raspberry-spi,代码行数:31,代码来源:devices-list.php


注:本文中的REST::response_code方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。