예제 #1
0
	<h2>Demo one</h2>
	<p>Search for packages containing &#8220;alcohol + beverage + licenses&#8221; using the default search options and manually output the results.</p>

	<?php 
try {
    // Search for packages containing "alcohol + beverage + licenses"
    $search_term = 'alcohol beverage licenses';
    $data = $ckan->search_package($search_term);
    // Display results
    if ($data) {
        printf('<h3>There %s %d result%s for &#8220;%s&#8221;:</h3>', $data->count === 1 ? 'is' : 'are', $data->count, $data->count === 1 ? '' : 's', $search_term);
        if ($data->count > 0) {
            print '<ol>';
            foreach ($data->results as $val) {
                $package = $ckan->get_package_entity($val);
                // The notes field uses the Markdown syntax, so
                // convert it to HTML using the PHP Markdown library
                printf('<li><a href="%s">%s</a>%s</li>', $package->ckan_url, $package->title, $package->notes ? ': ' . strip_tags(Markdown($package->notes), '<a>') : '');
            }
            print '</ol>';
        }
    }
} catch (Exception $e) {
    print '<p><strong>Caught exception: ' . $e->getMessage() . '</strong></p>';
}
?>

	<h2>Demo two</h2>
	<p>Search for packages containing &#8220;osm&#8221; using the alias functions and search options: <code>$ckan->search($search_term, array('order_by' => 'title', 'offset' => 1, 'limit' => 2, 'openness' => 1, 'downloadable' => 1));</code> and then manually output the results.</p>
예제 #2
0
        for ($i = 0; $i < 2; $i++) {
            print '<li>' . $data[$i] . '</li>';
        }
        print '</ul>';
    }
} catch (Exception $e) {
    print '<p><strong>Caught exception: ' . $e->getMessage() . '</strong></p>';
}
?>

	<h2>Demo two</h2>
	<p>Make a <code>GET</code> request to the package entity resource and manually output some fields.</p>

	<?php 
try {
    $data = $ckan->get_package_entity('mke-liquor-licenses');
    if ($data) {
        print '<blockquote><h3>' . $data->title . '</h3><p><strong>' . $data->maintainer . '</strong></p>' . Markdown($data->notes) . '<p><strong>License:</strong> ' . $data->license . '<br />&#8226; <a href="' . $data->ckan_url . '">View this package at CKAN</a></p></blockquote>';
    }
} catch (Exception $e) {
    print '<p><strong>Caught exception: ' . $e->getMessage() . '</strong></p>';
}
?>

	<h3>Demo three</h3>
	<p>Make a <code>POST</code> request to the package register resource to create a new package. <em>Note:</em> This demo requires an <abbr title="Application Programming Interface">API</abbr> key.</p>

	<?php 
try {
    $data = '{
				"name": "Name-String",