PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > Laravel教程 > 正文

    laravel框架添加成功失败跳转提示页面

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:在laravel里添加一个全局公共函数,如果你还不知道如果添加,请查看这篇文章【laravel 5.4添加全局公共函数】1.我们现在建一个 全局函数...
    在laravel里添加一个全局公共函数,如果你还不知道如果添加,请查看这篇文章【laravel 5.4添加全局公共函数

    1.我们现在建一个  全局函数文件Helpers.php

    里面代码如下:

    1. /** 
    2.  * 跳转提示函数 
    3.  */ 
    4. function showMessage(Array $array){ 
    5.  
    6.     //验证参数 
    7.     if(!emptyempty($array['message']) && !emptyempty($array['url'])){ 
    8.         $data = [ 
    9.             'message' => $array['message'], 
    10.             'url' => $array['url'], 
    11.             'jumpTime' => !emptyempty($array['time']) ? $array['time'] : 2000, 
    12.             'ok'=>!emptyempty($array['ok']) ? $array['ok'] : true 
    13.         ]; 
    14.     } else { 
    15.         $data = [ 
    16.             'message' => '非法访问!'
    17.             'url' => 'javascript:history.back();'
    18.             'jumpTime' => 2000, 
    19.             'ok'=>!emptyempty($array['ok']) ? $array['ok'] : true 
    20.         ]; 
    21.     } 
    22.     return view('admin.message',['data' => $data]); 
    23.  
    24.   //  return redirect('/message')->with($array); 

    2.模板页面代码如下:
     

    1. @extends('layouts.admin') 
    2. @section('styles') 
    3.     <style type="text/css"> 
    4.         .body-bgcolor{ background-color: #fff} 
    5.     .showMsg{border: 1px solid #1e64c8; zoom:1; width:450px; height:172px;position:absolute;top:44%;left:50%;margin:-87px 0 0 -225px} 
    6.     .showMsg h5{margin:0px;background-image: url({{asset('images/message/msg.png')}});background-repeat: no-repeat; color:#fff; padding-left:35px; height:25px; line-height:26px;*line-height:28px; overflow:hidden; font-size:14px; text-align:left} 
    7.     .showMsg .content{ padding:46px 12px 73px 45px; font-size:14px; height:64px;display: inline-block;} 
    8.     .showMsg .bottom{ background:#e4ecf7; margin: 0 1px 1px 1px;line-height:26px; *line-height:30px; height:26px; text-align:center} 
    9.     .showMsg .ok,.showMsg .guery{background: url({{asset('images/message/msg_bg.png')}}) no-repeat 0px -560px;} 
    10.     .showMsg .guery{background-position: left -460px;} 
    11.     </style> 
    12.     @endsection 
    13. @section('content') 
    14.     <div class="panel-body"> 
    15.         <div class="showMsg" style="text-align:center"> 
    16.             <h5>提示信息</h5> 
    17.             <div class="content guery">{{ $data['message'] }}</div> 
    18.             <div class="bottom"> 
    19.                 @if($data['url'] == 'goback') 
    20.  
    21.                     @else 
    22.                     <a href="{{ $data['url']}}">如果您的浏览器没有自动跳转,请点击这里</a> 
    23.                     @endif 
    24.  
    25.                 @if($data['ok']) 
    26.                 <script language="javascript">setTimeout("goUrl('{{ $data['url']}}')",{{ $data['jumpTime'] }});</script> 
    27.                     @endif 
    28.             </div> 
    29.         </div> 
    30.     </div> 
    31.     @endsection 

    3.控制器里使用代码如下:
     

    1. return showMessage(['message'=>'修改失败!','url' =>url('subject/index')]); 
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-153-5824-1.html
    相关热词搜索: