在使用tp6框架后发现作者取消了像之前tp5的跳转,并且使用$this->success() $this->error() redirect() 这种转跳方法会报一个Call to undefined method xxx::success()的错误,官方文档:https://www.kancloud.cn/manual/thinkphp6_0/1037654
但是也有方法回到之前的跳转,你可以安装下面的扩展用于支持旧版本的跳转操作
操作: cd 项目根目录 执行
composer require liliuwei/thinkphp-jump
然后到BaseController.php里面
use \liliuwei\think\Jump;
use Jump;
新建控制器继承Base基类控制器再使用$this->success() $this->error() redirect()等方法就不会报错了。
跳转界面丑怎么自定义的问题:
跳转模板文件在
tp5自带跳转不用安装扩展 /xxx/thinkphp/tpl/dispatch_jump.tpl
tp6安装扩展后在 /xxx/vendor/liliuwei/thinkphp-jump/src/tpl/dispatch_jump.tpl
其实tpl就是一个html网页文件,想要设计成自定义的可以自己尝试修改即可,提供一个我写好的模板文件,用的是layer的弹层
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
<title>跳转提示</title>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="/static/plugins/layer/layer.js"></script>
</head>
<body>
<!--<div class="system-message">
<?php switch ($code) {?>
<?php case 1:?>
<h1>:)</h1>
<p class="success"><?php echo(strip_tags($msg));?></p>
<?php break;?>
<?php case 0:?>
<h1>:(</h1>
<p class="error"><?php echo(strip_tags($msg));?></p>
<?php break;?>
<?php } ?>
<p class="detail"></p>
<p class="jump">
页面自动 <a id="href" href="<?php echo($url);?>">跳转</a> 等待时间: <b id="wait"><?php echo($wait);?></b>
</p>
</div>-->
<input type="hidden" id="msg" name="" value="<?php echo(strip_tags($msg));?>">
<input type="hidden" id="url" name="" value="<?php echo($url);?>">
<input type="hidden" id="wait" name="" value="<?php echo($wait);?>">
<input type="hidden" id="code" name="" value="<?php if($code == 1){echo 1;}else{echo 2;};?>">
<script type="text/javascript">
(function(){
var msg = $("#msg").val();
var url = $("#url").val();
var wait = $("#wait").val();
var code = $("#code").val();
layer.open({
content: msg,
icon: code,
yes: function(index,layero){
//do something
location.href=url;
layer.close(index);
}
});
// var wait = document.getElementById('wait'),
// href = document.getElementById('href').href;
var interval = setInterval(function(){
var time = --wait;
if(time <= 0) {
location.href = url;
clearInterval(interval);
};
}, 1000);
})();
</script>
</body>
</html>