改进Response类的send方法 去除 REQUEST_METHOD IS_GET IS_POST IS_PUT IS_DELETE IS_AJAX __EXT__ 常量 由应用自己定义

This commit is contained in:
thinkphp
2016-06-02 12:13:00 +08:00
parent ee9d5df56f
commit 8099a001e2
7 changed files with 63 additions and 32 deletions

View File

@@ -16,6 +16,7 @@ namespace traits\controller;
use think\Config;
use think\exception\HttpResponseException;
use think\Request;
use think\Response;
use think\response\Redirect;
use think\View as ViewTemplate;
@@ -46,7 +47,7 @@ trait Jump
'wait' => $wait,
];
$type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type');
$type = $this->getResponseType();
if ('html' == strtolower($type)) {
$result = ViewTemplate::instance(Config::get('template'), Config::get('view_replace_str'))
->fetch(Config::get('dispatch_success_tmpl'), $result);
@@ -78,7 +79,7 @@ trait Jump
'wait' => $wait,
];
$type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type');
$type = $this->getResponseType();
if ('html' == strtolower($type)) {
$result = ViewTemplate::instance(Config::get('template'), Config::get('view_replace_str'))
->fetch(Config::get('dispatch_error_tmpl'), $result);
@@ -120,4 +121,14 @@ trait Jump
throw new HttpResponseException($response);
}
/**
* 获取当前的response 输出类型
* @access public
* @return string
*/
public function getResponseType()
{
$isAjax = Request::instance()->isAjax();
return $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
}
}