Files
sentcms/app/http/middleware/Front.php
molong 0b0d659c5e tp6更新到最新版本
目录结构调整
2019-09-12 23:57:10 +08:00

52 lines
1.4 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\http\middleware;
use think\facade\View;
/**
* @title 后台中间件
*/
class Front {
protected $data = [];
public function handle($request, \Closure $next) {
$response = $next($request);
$this->data = $response->getData();
if ($request->isAjax()) {
return json($this->data);
}else{
return $response->data($this->fetch());
}
}
/**
* @title 显示类
*/
protected function fetch($template = ''){
// 使用内置PHP模板引擎渲染模板输出
$config = array(
'tpl_replace_string' => array(
'__static__' => '/static',
'__img__' => '/static/front/images',
'__css__' => '/static/front/css',
'__js__' => '/static/front/js',
'__public__' => '/static/front',
)
);
if (is_string($this->data)) {
$this->data = array('data' => $this->data);
}
View::config($config);
View::assign($this->data);
return View::engine('Think')->fetch($template);
}
}