tp6更新到最新版本
目录结构调整
This commit is contained in:
62
app/http/middleware/Admin.php
Normal file
62
app/http/middleware/Admin.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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 Admin {
|
||||
|
||||
protected $data = [];
|
||||
|
||||
public function handle($request, \Closure $next) {
|
||||
$response = $next($request);
|
||||
|
||||
if (is_array($response->getData())) {
|
||||
$this->data = array_merge($this->data, $response->getData());
|
||||
} else {
|
||||
$this->data = $response->getData();
|
||||
}
|
||||
|
||||
if ($request->isAjax()) {
|
||||
if (isset($this->data['config'])) {
|
||||
unset($this->data['config']);
|
||||
}
|
||||
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',
|
||||
),
|
||||
);
|
||||
|
||||
$template = (isset($this->data['template']) && $this->data['template']) ? $this->data['template'] : $template;
|
||||
|
||||
View::config($config);
|
||||
View::assign('sent_version', sent_version);
|
||||
View::assign('config', (isset($this->data['config']) ? $this->data['config'] : []));
|
||||
View::assign((isset($this->data['data']) ? $this->data['data'] : []));
|
||||
return View::fetch($template);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user