本文整理匯總了PHP中core\View::partial方法的典型用法代碼示例。如果您正苦於以下問題:PHP View::partial方法的具體用法?PHP View::partial怎麽用?PHP View::partial使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類core\View
的用法示例。
在下文中一共展示了View::partial方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: findOne
public function findOne($name, $type)
{
$page = $this->models->pageModel->findOneByName($name);
if (!isset($page)) {
$this->render404();
return;
}
switch ($type) {
case 'html':
/** @var Page $page */
$this->render('/page', ['content' => $page->getContent()]);
break;
case 'xml':
$xml = new \SimpleXMLElement("<xml/>");
$variables = (array) $page;
foreach ($variables as $key => $variable) {
$key = str_replace("models\\Page", "", $key);
$xml->addChild($key, $variable);
}
header("Content-Type: application/xml");
echo $xml->saveXML();
break;
case 'json':
$variables = (array) $page;
$json = [];
foreach ($variables as $key => $variable) {
$oldKey = $key;
$key = str_replace("models\\Page", "", $key);
$json[$key] = $variables[$oldKey];
}
$json['content'] = View::partial("page", ['content' => $page->getContent()]);
if (array_key_exists('redirect', $_GET) && $_GET['redirect'] === 'true') {
$json['header'] = $this->partial('header', ['user' => $this->user, 'pages' => $this->pages]);
}
$this->echo_json_encode($json);
break;
default:
$this->render404();
}
}
示例2: partial
protected function partial($viewName, $data = [])
{
return View::partial($viewName, $data);
}