首页 > 编程 > PHP > 正文

基于PHP的跳转提示框的实现示例

2020-03-22 18:13:05
字体:
来源:转载
供稿:网友
在PHP开发中,尤其是MVC框架或者项目中,会碰到很多跳转情况,比如:登录成功或失败后的跳转等等。

本篇文章的主要内容是基于PHP的跳转提示框的实现过程,附上代码,有需要的朋友可以参考一下。

以下以MVC框架开发中为基础,示例讲解:

在基础控制器类中:Conrtoller.html' target='_blank'>class.php


 ?php * 基础控制器类class Controller { * 跳转 * $url 目标url * $info 提示信息 * $time 等待时间(单位秒) protected function jump($url,$info=NULL,$time=3) { //判断是立即跳转还是刷新跳转 if(is_null($info)) { //立即跳转 header( location: . $url); die; } else { //刷新跳转,给出提示 echo TIAOZHUAN meta http-equiv= Content-Type content= text/html; charset=utf-8 /  title 提示信息 /title  style type= text/css  * {margin:0; padding:0;} div {width:390px; height:287px; border:1px #09C solid; position:absolute; left:50%; margin-left:-195px; top:10%;} div h2 {width:100%; height:30px; line-height:30px; background-color:#09C; font-size:14px; color:#FFF; text-indent:10px;} div p {height:120px; line-height:120px; text-align:center;} div p strong {font-size:26px;} /style  div  h2 提示信息 /h2  strong $info /strong br /  页面在 span id= second $time /span 秒后会自动跳转,或点击 a id= tiao href= $url 立即跳转 /a  /div  script type= text/javascript  var url = document.getElementById( tiao ).href; function daoshu(){ var scd = document.getElementById( second  var time = --scd.innerHTML; if(time =0){ window.location.href = url; clearInterval(mytime); var mytime = setInterval( daoshu() ,1000); /script TIAOZHUAN; die;}

在MVC的自动加载中,将Controller.class.php进行自动加载注册

通过不同控制器类继承上面的Controller.class.php基础控制器类后,就可以调用定义的跳转提示。


 ?php * 后台管理员控制器(登录、注销、管理员的增删改查等)class AdminController extends Controller { * 展示登录表单动作 public function loginAction() { // 载入当前的视图文件 $this- display( login.html  * 后台注销功能 public function logoutAction() { @session_start(); // 删除相关会话数据 unset($_SESSION[ adminInfo  // 删除会话数据区 session_destroy(); // 立即跳转到登录页面 $this- jump( index.php?c=Admin a=login , 您已退出后台登录! }

当然,这里是在MVC中实现的,你也可以把jump()单独提出来进行使用。

附上一个效果图:

相关教程:PHP视频教程

以上就是基于PHP的跳转提示框的实现示例的详细内容,PHP教程

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表