清除tp中默认session作用域
//检查是否登录
public function __construct(Request $request){
parent::__construct($request);
if(!session('?userid','','')){
$this->error('请先登录!','index/login/login');
}
}
session('名称',‘值’,‘前缀’)
- 设置前缀为空字符串
随之也修改session方法中
protected function success($msg ='',$url=null,$data='',$wait=3,array $header=[],$parent='')
将$result=[...]
参数加入'parent'=>$parent,
在最后一个参数加入$parent=''
session('成功','index',[],3,[],'parent');
最后一个参数为跳转的方式
在$result中添加'parent'=>$parent,
修改session作用域这一步骤可以省略,
目的是避免session中多个作用域冲突
修改跳转模板参数
模板地址:thinkphp/library/tpl/dispatch_jump.tpl
在location.href = href;代码前加入判断
<?php echo($parent?$parent.'.':'')?>
来根据session(‘’,‘’,‘parent’)来决定跳转的方式。
同样error方法还有点击跳转也要加
点击跳转的a标签加 target="_parent"
总结
success的跳转默认是在当前框架中子框架中跳转页面,
想要跳出整个框架,需要用到js/jq的跳转代码location.href
前面加上parent.
这样就可以跳出框架的限制。
附加-其他解决方式
<script>
if(window.top!=window){
window.top.location.href=document.location.href;
}
</script>
评论