* zin: support for rendering page with difference widget for ajax request.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The render function file of zin of ZenTaoPMS.
|
||||
*
|
||||
@@ -14,34 +15,47 @@ namespace zin;
|
||||
require_once __DIR__ . DS . 'zin.class.php';
|
||||
|
||||
/**
|
||||
* Render page content with a widget to HTML.
|
||||
* 将视图页面声明的所有内容通过一个部件进行渲染,并输出 HTML。
|
||||
* Render page content with a widget to HTML.
|
||||
*
|
||||
* @access public
|
||||
* @param string $wgName
|
||||
* @param string|array $options
|
||||
* @param string $wgName
|
||||
* @param string|array $options
|
||||
* @return void
|
||||
*/
|
||||
function render(string $wgName = 'page', string|array $options = null)
|
||||
{
|
||||
$args = array();
|
||||
/* 获取全局渲染部件实例和指令。 Get global render widgets and directives. */
|
||||
$globalItems = array();
|
||||
foreach(zin::$globalRenderList as $item)
|
||||
{
|
||||
if(is_object($item) && isset($item->parent) && $item->parent) continue;
|
||||
$args[] = $item;
|
||||
$globalItems[] = $item;
|
||||
}
|
||||
zin::$globalRenderList = array();
|
||||
zin::$globalRenderList = array(); // Clear globalRenderList.
|
||||
|
||||
/* 决定部件名称,如果是 Ajax 请求则进行特殊处理。 Decide widget name, if is ajax request, then do special process. */
|
||||
list($normalWgName, $ajaxWgName) = array_merge(explode('|', $wgName), array(''));
|
||||
$wgName = (!empty($ajaxWgName) && isAjaxRequest()) ? $ajaxWgName : $normalWgName;
|
||||
if(empty($wgName)) $wgName = 'page';
|
||||
|
||||
/* 判断是否渲染为完整页面。 Check if render in full page. */
|
||||
$isFullPage = str_starts_with($wgName, 'page');
|
||||
if($isFullPage) $args[] = set::display(false);
|
||||
if($isFullPage) $globalItems[] = set::display(false);
|
||||
|
||||
/* 获取部件渲染选项。 Get widget display options. */
|
||||
if($options === null && isset($_SERVER['HTTP_X_ZIN_OPTIONS']) && !empty($_SERVER['HTTP_X_ZIN_OPTIONS']))
|
||||
{
|
||||
$setting = $_SERVER['HTTP_X_ZIN_OPTIONS'];
|
||||
$options = $setting[0] === '{' ? json_decode($setting, true) : array('selector' => $setting);
|
||||
}
|
||||
|
||||
$wg = createWg($wgName, $args);
|
||||
if(!$isFullPage) $wg = fragment($wg);
|
||||
/* 创建部件实例。 Create widget instance. */
|
||||
$wg = createWg($wgName, $globalItems);
|
||||
|
||||
/* 如果不是渲染一个完整页面,则使用 fragment 进行渲染。 If not render in full page, then render all items in a fragment. */
|
||||
if(!$isFullPage && $wgName !== 'fragment') $wg = fragment($wg);
|
||||
|
||||
/* 渲染并输出 HTML。 Render and display html. */
|
||||
$wg->display($options);
|
||||
}
|
||||
|
||||
@@ -73,3 +73,8 @@ function isFieldRequired($name)
|
||||
|
||||
return $required;
|
||||
}
|
||||
|
||||
function isAjaxRequest()
|
||||
{
|
||||
return \helper::isAjaxRequest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user