mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
配置文件调整
控制器类的ajaxReturn方法调整
This commit is contained in:
@@ -26,17 +26,17 @@ class App {
|
||||
static public function run($config) {
|
||||
|
||||
// 日志初始化
|
||||
Log::init(['type'=>$config['log_type'],'log_path'=> $config['log_path']]);
|
||||
Log::init($config['log']);
|
||||
|
||||
// 缓存初始化
|
||||
Cache::connect(['type'=>$config['cache_type'],'temp'=> $config['cache_path']]);
|
||||
Cache::connect($config['cache']);
|
||||
|
||||
// 加载框架底层语言包
|
||||
is_file(THINK_PATH.'Lang/'.strtolower(Config::get('default_lang')).EXT) && Lang::set(include THINK_PATH.'Lang/'.strtolower(Config::get('default_lang')).EXT);
|
||||
|
||||
// 启动session
|
||||
if(!IS_CLI) {
|
||||
Session::init(['prefix'=>$config['session_prefix'],'auto_start'=>$config['session_auto_start']]);
|
||||
Session::init($config['session']);
|
||||
}
|
||||
if(is_file(APP_PATH.'build.php')) { // 自动化创建脚本
|
||||
Create::build(include APP_PATH.'build.php');
|
||||
@@ -274,7 +274,7 @@ class App {
|
||||
|
||||
unset($_GET[$config['var_action']], $_GET[$config['var_controller']], $_GET[$config['var_module']]);
|
||||
//保证$_REQUEST正常取值
|
||||
$_REQUEST = array_merge($_POST, $_GET);
|
||||
$_REQUEST = array_merge($_POST, $_GET , $_COOKIE);
|
||||
}
|
||||
|
||||
static private function getModule($config){
|
||||
|
||||
14
library/think/cache/driver/file.php
vendored
14
library/think/cache/driver/file.php
vendored
@@ -23,7 +23,7 @@ class File {
|
||||
'path_level' => 1,
|
||||
'prefix' => '',
|
||||
'length' => 0,
|
||||
'temp' => '',
|
||||
'path' => '',
|
||||
'data_compress' => false,
|
||||
];
|
||||
|
||||
@@ -35,7 +35,7 @@ class File {
|
||||
if(!empty($options)) {
|
||||
$this->options = array_merge($this->options,$options);
|
||||
}
|
||||
if(substr($this->options['temp'], -1) != '/') $this->options['temp'] .= '/';
|
||||
if(substr($this->options['path'], -1) != '/') $this->options['path'] .= '/';
|
||||
$this->init();
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ class File {
|
||||
*/
|
||||
private function init() {
|
||||
// 创建项目缓存目录
|
||||
if (!is_dir($this->options['temp'])) {
|
||||
if (! mkdir($this->options['temp'],0755))
|
||||
if (!is_dir($this->options['path'])) {
|
||||
if (! mkdir($this->options['path'],0755))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -67,14 +67,14 @@ class File {
|
||||
for($i=0;$i<$len;$i++) {
|
||||
$dir .= $name{$i}.'/';
|
||||
}
|
||||
if(!is_dir($this->options['temp'].$dir)) {
|
||||
mkdir($this->options['temp'].$dir,0755,true);
|
||||
if(!is_dir($this->options['path'].$dir)) {
|
||||
mkdir($this->options['path'].$dir,0755,true);
|
||||
}
|
||||
$filename = $dir.$this->options['prefix'].$name.'.php';
|
||||
}else{
|
||||
$filename = $this->options['prefix'].$name.'.php';
|
||||
}
|
||||
return $this->options['temp'].$filename;
|
||||
return $this->options['path'].$filename;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
6
library/think/cache/driver/secache.php
vendored
6
library/think/cache/driver/secache.php
vendored
@@ -20,7 +20,7 @@ class Secache {
|
||||
protected $handler = null;
|
||||
protected $options = [
|
||||
'project' => '',
|
||||
'temp' => '',
|
||||
'path' => '',
|
||||
'expire' => 0,
|
||||
'prefix' => '',
|
||||
'length' => 0,
|
||||
@@ -35,9 +35,9 @@ class Secache {
|
||||
if(!empty($options)) {
|
||||
$this->options = array_merge($this->options,$options);
|
||||
}
|
||||
if(substr($this->options['temp'], -1) != '/') $this->options['temp'] .= '/';
|
||||
if(substr($this->options['path'], -1) != '/') $this->options['path'] .= '/';
|
||||
$this->handler = new SecacheClient;
|
||||
$this->handler->workat($this->options['temp'].$this->options['project']);
|
||||
$this->handler->workat($this->options['path'].$this->options['project']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
6
library/think/cache/driver/simple.php
vendored
6
library/think/cache/driver/simple.php
vendored
@@ -19,7 +19,7 @@ class Simple {
|
||||
|
||||
protected $options = [
|
||||
'prefix' => '',
|
||||
'temp' => '',
|
||||
'path' => '',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ class Simple {
|
||||
if(!empty($options)) {
|
||||
$this->options = array_merge($this->options,$options);
|
||||
}
|
||||
if(substr($this->options['temp'], -1) != '/') $this->options['temp'] .= '/';
|
||||
if(substr($this->options['path'], -1) != '/') $this->options['path'] .= '/';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +40,7 @@ class Simple {
|
||||
* @return string
|
||||
*/
|
||||
private function filename($name) {
|
||||
return $this->options['temp'].$this->options['prefix'].md5($name).'.php';
|
||||
return $this->options['path'].$this->options['prefix'].md5($name).'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,7 @@ class Config {
|
||||
|
||||
// 获取配置参数 为空则获取所有配置
|
||||
static public function get($name=null,$range='') {
|
||||
$range = $range?$range:self::$_range;
|
||||
$range = $range ? $range : self::$_range;
|
||||
// 无参数时获取所有
|
||||
if (empty($name)) {
|
||||
return self::$_config[$range];
|
||||
@@ -67,7 +67,7 @@ class Config {
|
||||
|
||||
// 设置配置参数 name为数组则为批量设置
|
||||
static public function set($name, $value=null,$range='') {
|
||||
$range = $range?$range:self::$_range;
|
||||
$range = $range ? $range : self::$_range;
|
||||
if(!isset(self::$_config[$range])) {
|
||||
self::$_config[$range] = [];
|
||||
}
|
||||
|
||||
@@ -73,42 +73,43 @@ class Controller {
|
||||
* @access protected
|
||||
* @param mixed $data 要返回的数据
|
||||
* @param String $type AJAX返回数据格式
|
||||
* @param mixed $fun 数据处理方法
|
||||
* @return void
|
||||
*/
|
||||
protected function ajaxReturn($data, $type='') {
|
||||
if(empty($type)) $type = Config::get('default_ajax_return');
|
||||
switch (strtoupper($type)){
|
||||
case 'JSON':
|
||||
// 返回JSON数据格式到客户端 包含状态信息
|
||||
header('Content-Type:application/json; charset=utf-8');
|
||||
$data = Transform::jsonEncode($data);
|
||||
break;
|
||||
case 'XML':
|
||||
// 返回xml格式数据
|
||||
header('Content-Type:text/xml; charset=utf-8');
|
||||
$data = Transform::xmlEncode($data);
|
||||
break;
|
||||
case 'JSONP':
|
||||
// 返回JSON数据格式到客户端 包含状态信息
|
||||
header('Content-Type:application/javascript; charset=utf-8');
|
||||
$handler = isset($_GET[C('var_jsonp_handler')]) ? $_GET[C('var_jsonp_handler')] : C('default_jsonp_handler');
|
||||
$data = $handler . '(' . Transform::jsonEncode($data) . ');';
|
||||
break;
|
||||
case 'SCRIPT':
|
||||
// 返回可执行的js脚本
|
||||
header('Content-Type:application/javascript; charset=utf-8');
|
||||
break;
|
||||
case 'HTML':
|
||||
// 返回html片段
|
||||
header('Content-Type:text/html; charset=utf-8');
|
||||
break;
|
||||
case 'TEXT':
|
||||
// 返回一段纯文本
|
||||
header('Content-Type:text/plain; charset=utf-8');
|
||||
break;
|
||||
default:
|
||||
// 用于扩展其他返回格式数据
|
||||
$data = Hook::listen('ajax_return', $data);
|
||||
protected function ajaxReturn($data, $type='',$fun='') {
|
||||
if(empty($type)) {
|
||||
$type = Config::get('default_ajax_return');
|
||||
}
|
||||
$headers = [
|
||||
'json' => 'application/json',
|
||||
'xml' => 'text/xml',
|
||||
'jsonp' => 'application/javascript',
|
||||
'script'=> 'application/javascript',
|
||||
'html' => 'text/html',
|
||||
'text' => 'text/plain',
|
||||
];
|
||||
$type = strtolower($type);
|
||||
if(isset($headers[$type])){
|
||||
header('Content-Type:'.$headers[$type].'; charset=utf-8');
|
||||
}
|
||||
if($fun && is_callable($fun)){
|
||||
$data = call_user_func($fun,$data);
|
||||
}else{
|
||||
switch ($type){
|
||||
case 'json':
|
||||
// 返回JSON数据格式到客户端 包含状态信息
|
||||
$data = Transform::jsonEncode($data);
|
||||
break;
|
||||
case 'xml':
|
||||
// 返回xml格式数据
|
||||
$data = Transform::xmlEncode($data);
|
||||
break;
|
||||
case 'jsonp':
|
||||
// 返回JSON数据格式到客户端 包含状态信息
|
||||
$handler = isset($_GET[Config::get('var_jsonp_handler')]) ? $_GET[Config::get('var_jsonp_handler')] : Config::get('default_jsonp_handler');
|
||||
$data = $handler . '(' . Transform::jsonEncode($data) . ');';
|
||||
break;
|
||||
}
|
||||
}
|
||||
exit($data);
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace think\log\driver;
|
||||
class File {
|
||||
|
||||
protected $config = [
|
||||
'log_time_format' => ' c ',
|
||||
'log_file_size' => 2097152,
|
||||
'log_path' => '',
|
||||
'time_format' => ' c ',
|
||||
'file_size' => 2097152,
|
||||
'path' => '',
|
||||
];
|
||||
|
||||
// 实例化并传入参数
|
||||
@@ -32,11 +32,11 @@ class File {
|
||||
* @return void
|
||||
*/
|
||||
public function write($log,$destination='') {
|
||||
$now = date($this->config['log_time_format']);
|
||||
$now = date($this->config['time_format']);
|
||||
if(empty($destination))
|
||||
$destination = $this->config['log_path'].date('y_m_d').'.log';
|
||||
$destination = $this->config['path'].date('y_m_d').'.log';
|
||||
//检测日志文件大小,超过配置大小则备份日志文件重新生成
|
||||
if(is_file($destination) && floor($this->config['log_file_size']) <= filesize($destination) )
|
||||
if(is_file($destination) && floor($this->config['file_size']) <= filesize($destination) )
|
||||
rename($destination,dirname($destination).'/'.time().'-'.basename($destination));
|
||||
error_log("[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n", 3,$destination);
|
||||
}
|
||||
|
||||
@@ -41,12 +41,6 @@ return [
|
||||
'var_jsonp_handler' => 'callback',
|
||||
'template_engine' => 'think',
|
||||
'common_module' => 'Common',
|
||||
'log_path' => LOG_PATH,
|
||||
'log_type' => 'File',
|
||||
'cache_type' => 'File',
|
||||
'caceh_path' => CACHE_PATH,
|
||||
'session_prefix' => 'think',
|
||||
'session_auto_start' => true,
|
||||
'action_bind_class' => false,
|
||||
'url_module_map' => [],
|
||||
|
||||
@@ -55,6 +49,24 @@ return [
|
||||
'error_page' => '', // 错误定向页面
|
||||
'show_error_msg' => false, // 显示错误信息
|
||||
|
||||
'log' => [
|
||||
'type' => 'File',
|
||||
'path' => LOG_PATH,
|
||||
]
|
||||
|
||||
'cache' => [
|
||||
'type' => 'File',
|
||||
'path' => CACHE_PATH,
|
||||
'prefix' => '',
|
||||
'expire' => 0,
|
||||
]
|
||||
|
||||
'session' => [
|
||||
'prefix' => 'think',
|
||||
'type' => '',
|
||||
'auto_start' => true,
|
||||
]
|
||||
|
||||
/* 数据库设置 */
|
||||
'database' => [
|
||||
'type' => 'mysql', // 数据库类型
|
||||
|
||||
Reference in New Issue
Block a user