通知设置 新通知
$this->error()无法跳转的坑!
delgo 发表了文章 • 0 个评论 • 1631 次浏览 • 2020-03-26 21:02
因为想做一个表单提交后发现某错误后跳转出去后台的功能,所以用到了$this->error($msg,$url),结果发现跳转完全不起作用。但是$this->success($msg,$url)跳转却可以。
看了看thinkphp官方的代码,没有发现自己传递参数时有啥错误。
代码在thinkphp/traits/controller/jump.php中。
/**
* 操作错误跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
*/
protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{
$type = $this->getResponseType();
if (is_null($url)) {
$url = $this->app['request']->isAjax() ? '' : 'javascript:history.back(-1);';
} elseif ('' !== $url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app['url']->build($url);
}
$result = [
'code' => 0,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
if ('html' == strtolower($type)) {
$type = 'jump';
}
$response = Response::create($result, $type)->header($header)->options(['jump_template' => $this->app['config']->get('dispatch_error_tmpl')]);
throw new HttpResponseException($response);
}
然后再看thinkphp文档,发现有一句error方法会自动判断当前请求是否属于Ajax请求,如果属于Ajax请求则会自动转换为default_ajax_return配置的格式返回信息。 success在Ajax请求下不返回信息,需要开发者自行处理。围绕这个找了半天,发现能力有限,确实翻找不到,最终在dolphin.js260行左右找到了代码。
tips(msg, 'danger');对表单提交时候的$this->error();有效,于是在下面加了一句。
if(res.url){
setTimeout(function(){
parent.location.href = res.url;
},res.wait*1000)
}这下可以实现了,但是其实根本的问题没能解决,也算是个BUG吧,请官方看看是哪里的问题。 查看全部
看了看thinkphp官方的代码,没有发现自己传递参数时有啥错误。
代码在thinkphp/traits/controller/jump.php中。
/**
* 操作错误跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
*/
protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{
$type = $this->getResponseType();
if (is_null($url)) {
$url = $this->app['request']->isAjax() ? '' : 'javascript:history.back(-1);';
} elseif ('' !== $url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app['url']->build($url);
}
$result = [
'code' => 0,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
if ('html' == strtolower($type)) {
$type = 'jump';
}
$response = Response::create($result, $type)->header($header)->options(['jump_template' => $this->app['config']->get('dispatch_error_tmpl')]);
throw new HttpResponseException($response);
}
然后再看thinkphp文档,发现有一句error方法会自动判断当前请求是否属于Ajax请求,如果属于Ajax请求则会自动转换为default_ajax_return配置的格式返回信息。 success在Ajax请求下不返回信息,需要开发者自行处理。围绕这个找了半天,发现能力有限,确实翻找不到,最终在dolphin.js260行左右找到了代码。
tips(msg, 'danger');对表单提交时候的$this->error();有效,于是在下面加了一句。
if(res.url){
setTimeout(function(){
parent.location.href = res.url;
},res.wait*1000)
}这下可以实现了,但是其实根本的问题没能解决,也算是个BUG吧,请官方看看是哪里的问题。 查看全部
因为想做一个表单提交后发现某错误后跳转出去后台的功能,所以用到了$this->error($msg,$url),结果发现跳转完全不起作用。但是$this->success($msg,$url)跳转却可以。
看了看thinkphp官方的代码,没有发现自己传递参数时有啥错误。
代码在thinkphp/traits/controller/jump.php中。
然后再看thinkphp文档,发现有一句
看了看thinkphp官方的代码,没有发现自己传递参数时有啥错误。
代码在thinkphp/traits/controller/jump.php中。
/**
* 操作错误跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
*/
protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{
$type = $this->getResponseType();
if (is_null($url)) {
$url = $this->app['request']->isAjax() ? '' : 'javascript:history.back(-1);';
} elseif ('' !== $url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app['url']->build($url);
}
$result = [
'code' => 0,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
if ('html' == strtolower($type)) {
$type = 'jump';
}
$response = Response::create($result, $type)->header($header)->options(['jump_template' => $this->app['config']->get('dispatch_error_tmpl')]);
throw new HttpResponseException($response);
}
然后再看thinkphp文档,发现有一句
error方法会自动判断当前请求是否属于Ajax请求,如果属于Ajax请求则会自动转换为default_ajax_return配置的格式返回信息。 success在Ajax请求下不返回信息,需要开发者自行处理。围绕这个找了半天,发现能力有限,确实翻找不到,最终在dolphin.js260行左右找到了代码。
tips(msg, 'danger');对表单提交时候的$this->error();有效,于是在下面加了一句。
if(res.url){这下可以实现了,但是其实根本的问题没能解决,也算是个BUG吧,请官方看看是哪里的问题。
setTimeout(function(){
parent.location.href = res.url;
},res.wait*1000)
}
按钮跳转以弹窗的形式,当携带参数id为160时无法进入跳转页面
dolphinphp 回复了问题 • 2 人关注 • 1 个回复 • 1716 次浏览 • 2020-01-03 10:11
生成模板报_message 未定义
单弦 回复了问题 • 3 人关注 • 2 个回复 • 1829 次浏览 • 2019-12-05 00:23
图片上传功能,没有记忆目录功能,浏览器没有开启隐身模式
huangda 回复了问题 • 2 人关注 • 1 个回复 • 1246 次浏览 • 2019-10-29 14:40
用户列表修改密码,做了正则验证非空以及字符要求,点击直接提交修改是会触发 非空验证的。这个密码修改能否展示,总不能每次修改用户信息都得修改一次密码吧
[已注销] 回复了问题 • 2 人关注 • 1 个回复 • 1345 次浏览 • 2019-05-10 09:32
后台门户-常用操作-文档列表-编辑文档-提示未定义数组索引: model
zs381764561 发表了文章 • 2 个评论 • 2120 次浏览 • 2019-02-28 17:59
后台门户-常用操作-文档列表-编辑文档-提示未定义数组索引: model
后台门户-常用操作-文档列表-编辑文档-提示未定义数组索引: model
系统设置重大bug
dolphinphp 回复了问题 • 2 人关注 • 1 个回复 • 1895 次浏览 • 2019-02-25 00:01