本文整理汇总了PHP中HTMLPage::setDataArray方法的典型用法代码示例。如果您正苦于以下问题:PHP HTMLPage::setDataArray方法的具体用法?PHP HTMLPage::setDataArray怎么用?PHP HTMLPage::setDataArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTMLPage
的用法示例。
在下文中一共展示了HTMLPage::setDataArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populateHTMLPage
/**
* Example page data ala: json_encode(CMSPage->data->seralize()):
* {
* layout: 'layout',
* doctype: 'xhtml 1.0',
* title: 'Page Title',
* description: 'Meta Description',
* keywords: ['meta', 'keywords'],
* meta: {
* other: 'meta values'
* },
* scripts: [
* 'some/script.js',
* ['or/something/odd.huh', 'mime/type']
* ],
* stylesheets: [
* { href: 'some/css',
* title: 'Optional Title',
* alt: false, // default
* media: 'optional media'
* }
* ],
* links: [
* { href: 'some/path',
* type: 'mime/type',
* rel: 'what',
* title: 'What'
* }
* ]
* }
*/
protected function populateHTMLPage(CMSPage $cpage, HTMLPage $hpage)
{
$d = $cpage->data->serialize();
if (array_key_exists('layout', $d)) {
$hpage->setLayout($d['layout']);
unset($d['layout']);
}
if (array_key_exists('doctype', $d)) {
$hpage->doctype = $d['doctype'];
unset($d['doctype']);
}
if (array_key_exists('title', $d)) {
$hpage->title = $d['title'];
unset($d['title']);
}
foreach (array('description', 'keywords') as $mk) {
if (array_key_exists($mk, $d)) {
$hpage->meta->set($mk, $d[$mk]);
unset($d[$mk]);
}
}
if (array_key_exists('meta', $d)) {
$hpage->meta->setArray($d['meta']);
unset($d['meta']);
}
if (array_key_exists('scripts', $d)) {
foreach ((array) $d['scripts'] as $script) {
$script = (array) $script;
assert(array_key_exists('href', $script));
$href = $script['href'];
$type = array_key_exists('type', $script) ? $script['type'] : null;
if (isset($type)) {
$a = new HTMLPageScript($href, $type);
} else {
$a = new HTMLPageScript($href);
}
$hpage->addAsset($a);
}
unset($d['scripts']);
}
if (array_key_exists('stylesheets', $d)) {
foreach ((array) $d['stylesheets'] as $style) {
$style = (array) $style;
assert(array_key_exists('href', $style));
$hpage->addAsset(new HTMLPageStylesheet($style['href'], array_key_exists('alt', $style) ? $style['alt'] : false, array_key_exists('title', $style) ? $style['title'] : null, array_key_exists('media', $style) ? $style['media'] : null));
}
unset($d['stylesheets']);
}
if (array_key_exists('links', $d)) {
foreach ((array) $d['links'] as $link) {
$link = (array) $link;
assert(array_key_exists('href', $link));
assert(array_key_exists('type', $link));
assert(array_key_exists('rel', $link));
$href = $link['href'];
$type = $link['type'];
$rel = $link['rel'];
$title = array_key_exists('title', $link) ? $link['title'] : null;
if ($rel == 'alternate') {
$a = new HTMLPageAlternateLink($href, $type, $title);
} else {
$a = new HTMLPageLinkedResource($href, $type, $rel, $title);
}
$hpage->addAsset($a);
}
unset($d['links']);
}
if (count($d)) {
$hpage->setDataArray($d);
//.........这里部分代码省略.........