Home >PHP Framework >ThinkPHP >ThinkPHP custom success and error jump pages

ThinkPHP custom success and error jump pages

angryTom
angryTomforward
2020-03-07 10:34:573725browse

This article introduces the method of customizing success and error jump pages in thinkphp5. It has certain reference value. I hope it will be helpful to friends who are learning the thinkphp framework!

ThinkPHP custom success and error jump pages

ThinkPHP custom success and error jump page

The jump template settings defined in thinkphp5 are in the directory It is defined by application\config.php and also defines the jump template file by default. The following is the code in config.php.

// 默认跳转页面对应的模板文件
    'dispatch_success_tmpl'  => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
    'dispatch_error_tmpl'    => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',

(Recommended tutorial: thinkphp tutorial)

With the above definition settings, we can quickly find the actual location of the default template, in the core file directory thinkphp\tpl \dispatch_jump.tpl. First, we want to customize the jump template file. We have two ideas. The first idea is that the template file should not be set, that is, delete the original content of the above thinkphp\tpl\dispatch_jump.tpl file and change it to Our own file contents. Another way of thinking is that we redefine the location of the jump file. We usually redefine dispatch_success_tmpl and dispatch_error_tmpl in the config folder under which project we need to jump. Here I take the admin project as an example. Its configuration file application\admin\config.php is defined as follows

<?php
//配置文件
return [
  //分页配置
  &#39;paginate&#39;               => [
      &#39;type&#39;      => &#39;bootstrap3&#39;,
      &#39;var_page&#39;  => &#39;page&#39;,
      &#39;list_rows&#39; => 15,
  ],
    // 默认跳转页面对应的模板文件
  &#39;dispatch_success_tmpl&#39;=>&#39;public:dispatch_jump&#39;,
  &#39;dispatch_error_tmpl&#39;=>&#39;public:dispatch_jump&#39;,
  // &#39;dispatch_success_tmpl&#39;  => THINK_PATH . &#39;tpl&#39; . DS . &#39;dispatch_jump.tpl&#39;,
  // &#39;dispatch_error_tmpl&#39;    => THINK_PATH . &#39;tpl&#39; . DS . &#39;dispatch_jump.tpl&#39;,
];

After the above definition and setting, the jump template file is in application\admin\view\public\dispatch_jump.html , the above is the setting method of thinkphp5, but thinkphp3.2 is different from this. The template path in 3.2 is different. If you want to set it up separately in a certain project directory, you must first create the conf folder and then create config in it. .php file, the following is the code of the default settings file in ThinkPHP\Conf\convention.php

  /* 模板引擎设置 */
    &#39;TMPL_CONTENT_TYPE&#39;     =>  &#39;text/html&#39;, // 默认模板输出类型
    &#39;TMPL_ACTION_ERROR&#39;     =>  THINK_PATH.&#39;Tpl/dispatch_jump.tpl&#39;, // 默认错误跳转对应的模板文件
    &#39;TMPL_ACTION_SUCCESS&#39;   =>  THINK_PATH.&#39;Tpl/dispatch_jump.tpl&#39;, // 默认成功跳转对应的模板文件

The last thing to note is that if the smart template engine is used, the 610f3e5a44564742a12f53bcf49de008For this, we just replace it with {$jumpUrl}. If it is thinkphp5, just change it to {url}.

For more thinkphp tutorials, please pay attention to PHP Chinese website!

The above is the detailed content of ThinkPHP custom success and error jump pages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:www.100txy.com. If there is any infringement, please contact admin@php.cn delete