Files
sentcms/app/middleware/Admin.php
2019-06-29 21:14:58 +08:00

47 lines
1.3 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\middleware;
use think\facade\View;
/**
* @title 后台中间件
*/
class Admin {
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/admin/images',
'__css__' => '/static/admin/css',
'__js__' => '/static/admin/js',
'__public__' => '/static/admin',
)
);
return View::config($config)->assign($this->data)->fetch($template);
}
}