/**
* 显示提示信息操作
*
* 所显示的提示信息并非完全是错误信息。如:用户登陆时用户名或密码错误,可用本方法输出提示信息
*
* 注:显示提示信息的页面模板内容可以自定义. 方法:在项目视图目录中的error子目录中新建message.html文件,自定义该文件内容
* 显示错误信息处模板标签为<!--{$message}-->
*
* 本方法支持URL的自动跳转,当显示时间有效期失效时则跳转到自定义网址,若跳转网址为空则函数不执行跳转功能,当自定义网址参数为-1时默认为:返回上一页。
* @access public
* @param string $message 所要显示的提示信息
* @param string $gotoUrl 所要跳转的自定义网址
* @param int $limitTime 显示信息的有效期,注:(单位:秒) 默认为5秒
* @return void
*/
public static function showMessage($message, $gotoUrl = null, $limitTime = 5) {
//参数分析
if (!$message) {
return false;
}
//当自定义跳转网址存在时
if (!is_null($gotoUrl)) {
$limitTime = 1000 * $limitTime;
//分析自定义网址是否为返回页
if ($gotoUrl == -1) {
$gotoUrl = 'javascript:history.go(-1);';
$message .= '<br/><a href="javascript:history.go(-1);" target="_self">如果你的浏览器没反应,请点击这里...</a>';
} else{
//防止网址过长,有换行引起跳转变不正确
$gotoUrl = str_replace(array("\n","\r"), '', $gotoUrl);
$message .= '<br/><a href="' . $gotoUrl . '" target="_self">如果你的浏览器没反应,请点击这里...</a>';
}
$message .= '<script type="text/javascript">function doit_redirect_url(url){location.href=url;}setTimeout("doit_redirect_url(\'' . $gotoUrl . '\')", ' . $limitTime . ');</script>';
}
$messageTemplateFile = VIEW_DIR . 'error/message.php';
is_file($messageTemplateFile) ? include_once $messageTemplateFile : include_once DOIT_ROOT . 'views/html/message.php';
exit();
}
test code
最新推荐文章于 2023-06-14 14:50:28 发布