首頁 php框架 ThinkPHP thinkphp6重定向提示

thinkphp6重定向提示

May 04, 2021 pm 06:51 PM
1

1、準備跳轉模板檔案

把舊的ThinkPHP 框架的中的跳轉模板檔案複製過來

位置在舊的框架核心檔案/thinkphp/tpl/dispatch_jump. tpl

例如放到:/public/tpl/dispatch_jump.tpl

#2、修改設定檔

位置在/config/app.php 把如下2行程式碼加在設定檔中,如下:

// 預設跳轉頁面對應的範本檔案【新增】
'dispatch_success_tmpl' => app()->getRootPath() . '/public/ tpl/dispatch_jump.tpl',
'dispatch_error_tmpl' => app()->getRootPath() . '/public/tpl/dispatch_jump.tpl',
———————————— ——————

3、修改基礎控制器類別

位置在/app/BaseController.php

(1)在頂部加上如下2行程式碼,引入的文件,如下:

//
// 下面2行,為了使用舊版的success error redirect 跳轉
//
use think\exception\HttpResponseException ;
use think\facade\Request;
————————————————

2)接下來,還是在這個基礎控制器類別檔案裡進行修改,直接加入如下程式碼:「

//
// 以下為新增,若要使用舊版的成功錯誤重定向跳轉圖片 start
//

/**
* 操作成功跳轉的快速方法
* @access protected
* @param  mixed     $msg 提示訊息
* @param  string    $url 跳躍的URL位址
> * @param  string    $url 跳轉的URL位址##mixed $data 回傳的資料
* @param  integer   $wait 跳轉等待時間
* @param  array     $header 傳送的Header訊息
* @return void
*/
protected function success ($msg = '', string $url = null, $data = '', int $wait = 3, array $header = [])
{
   if (is_null($url) && isset($ _SERVER["HTTP_REFERER"])) {
       $url = $_SERVER["HTTP_REFERER"];
   } elseif ($url) {## ://' ) || 0 === strpos($url, '/')) ? $url : app('route')->buildUrl($url);
   }

   $result = [
      'code' =>; 1、
      'msg' => $msg,
      '資料' => $data,
      'url' => $url,
       '等待' => $wait,
   ];

   $type = $this->getResponseType();
   if ($type == 'html'){
       $response = view(thisponse = view(this -ponse = view(thisponse = view(thisponse = view) >app->config->get('app.dispatch_success_tmpl'), $result);
   } else if ($type == 'json') {
       $response = json($result );
   }
   拋出新的HttpResponseException($response);
}

/**
* 操作錯誤跳轉的快速方法
* @access protected
* @param  mixed     $msg 提示訊息
* @param  string    $url 跳轉的URL「 」位址#」位址$data 回傳的資料
* @param  integer   $wait 跳轉等待時間
* @param  array     $header 傳送的Header訊息
* @return void
*/
受保護的函式錯誤($msg = '', string $ url = null, $data = '', int $wait = 3, array $header = [])
{
   if (is_null($url)) {
       $url = $this->請求->isAjax() ? '' : 'javascript:history.back(-1);';
   } elseif ($url) {
       $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app->route->buildUrl($url);
   }

   $result = [
      'code' =>; 0,
      'msg' => $msg,
      '資料' => $data,
      'url' => $url,
      '等待' => $wait,
   ];

   $type = $this->getResponseType();
   if ($type == 'html'){
       $response = view(thisponse = view(this -ponse = view(thisponse = view(thisponse = view) >app->config->get('app.dispatch_error_tmpl'), $result);
   } else if ($type == 'json') {
       $response = json($result );
   }
   拋出新的HttpResponseException($response);
}

/**
* URL重定向 自帶重定向無效
* @access protected
* @param  string         $url 跳轉的URL表達式
* @param  array|integer  $params 其它URL參數
* @param  array|integer  $params 其它URL參數參數
* @param  integer        $code http code
* @param  array          $with 隱式傳參
* @return void
#*/
protected 函數重新導向($url, $params = [] , $code = 302, $with = [])
{
   $response = Response::create($url, 'redirect');

   if (is_integer($params)) {
       $code = $params;
       $params = [];
   }

#    $response->code($code)->params($
#    $response->code($code)->params($params)->with$. ;

   拋出新的HttpResponseException($response);
}

/**
* 取得目前的response 輸出類型
* @access protected
* @return string
*/
protected function getResponseType()
{
返回$this->request->isJson() || $this->請求->isAjax() ? 'json' : 'html';
}

//
// 以上為新增,若要使用舊版的成功錯誤重定向跳轉 end
//

使用重定向提示3秒後跳躍程式碼提示案例如下

//驗證失敗做處理
           $p = $v->getError(); //提示的資訊是驗證器裡的錯誤訊息
           $this->success($p, url('/admin/index/Add_order_list/')); //重定向並提示訊息

以上是thinkphp6重定向提示的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1666
14
CakePHP 教程
1425
52
Laravel 教程
1325
25
PHP教程
1273
29
C# 教程
1252
24