本文整理汇总了PHP中API::Sites方法的典型用法代码示例。如果您正苦于以下问题:PHP API::Sites方法的具体用法?PHP API::Sites怎么用?PHP API::Sites使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::Sites方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PerformTest
public function PerformTest()
{
// Note that API::Sites does NOT return a paged
// request object, but a derivitave of PagedResponse
// Enumerate all Stack Exchange sites
$sites = API::Sites();
$count = 0;
// count the sites
while ($site = $sites->Fetch()) {
if (!isset($site['name'])) {
throw new Exception('Site array returned is invalid.');
}
++$count;
}
if ($count < 100) {
throw new Exception('Expected more than 100 Stack Exchange sites.');
}
// the StackAuth /users/{GUID}/associated route
$response = API::AssociatedUsers(1);
if ($response->Total() < 50) {
throw new Exception('Expected more than 50 associated accounts - only ' . $response->Total() . ' returned.');
}
}
示例2:
<?php
// Simple example that demonstrates listing users from a
// Stack Exchange site. Makes use of the output helper functions.
require_once 'config.php';
require_once '../../src/output_helper.php';
// Generate the site combobox
$combo = OutputHelper::CreateCombobox(API::Sites(), 'site');
$site_html = $combo->FetchMultiple()->SetIndices('name', 'api_site_parameter')->SetCurrentSelection()->GetHTML();
?>
<!DOCTYPE html>
<html>
<head>
<title>Stack.PHP - User List</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel='stylesheet' type='text/css' href='../common/style.css' />
</head>
<body>
<form id='form'>
<div id='site_selector'>
<b>Select a Stack Exchange site:</b>
<?php
echo $site_html;
?>
<input type="submit" value="Go" />
</div>
<?php
if (isset($_GET['site'])) {
$site = API::Site($_GET['site']);
$request = $site->Users();
if (isset($_GET['sort'])) {
示例3: header
<?php
// Demonstrates how Stack.PHP's data retrieval methods can
// be exposed to other clients, such as JavaScript code.
require_once 'config.php';
// The very first thing we do is output CORS headers
header('Access-Control-Allow-Methods: POST, GET');
header('Access-Control-Allow-Origin: *');
// Retrieve all Stack Exchange sites across all pages.
$response = API::Sites();
// Build an array with the response
$sites = array();
while ($site = $response->Fetch(TRUE)) {
$sites[] = $site->Data();
}
// Encode the data as JSON
$json = json_encode(array('items' => $sites, 'has_more' => FALSE));
// Output the data according to the parameters specified
if (isset($_GET['callback'])) {
header('Content-type: application/javascript');
echo "{$_GET['callback']}({$json});";
} else {
header('Content-type: application/json');
echo $json;
}
示例4: index
public function index()
{
$this->SetPageInfo('Stack Exchange Sites', 'http://stackexchange.com/sites');
$this->SetViewVariable('response', API::Sites());
}
示例5: stdClass
$campaign = new stdClass();
}
?>
<li class="type-text" id="container-autoposting_campaign_name">
<fieldset class="title">
<div class="inner">
<label for="autoposting_campaign_name">Campaign name</label>
<kbd>Set autoposting campaign name</kbd> </div>
</fieldset>
<fieldset class="data">
<div class="inner">
<input type="text" name="autoposting_campaign_name" value="<?php
echo isset($campaign->campaign_name) ? $campaign->campaign_name : '';
?>
" id="autoposting_campaign_name" />
</div>
</fieldset>
<div class="clear"></div>
</li>
<li class="type-text" id="container-autoposting_search_term">
<fieldset class="title">
<div class="inner">
<label for="autoposting_search_term">Search Term</label>
<kbd>Set search term</kbd> </div>
</fieldset>