Home > PHP Framework > ThinkPHP > body text

How to jump to the parent page in thinkphp success

PHPz
Release: 2023-04-17 10:33:23
Original
827 people have browsed it

With the popularity of web development, more and more developers use PHP as a back-end language. Among the PHP frameworks, ThinkPHP is widely used because it is easy to learn, easy to use and powerful. In ThinkPHP, we often encounter the need to jump to the parent page after completing certain operations in the child page. This article will introduce how to use ThinkPHP to implement the function of jumping to the parent page after success.

1. What is jumping to the parent page?

In Web development, jumping to the parent page refers to jumping from the current page to the page that opens the page. For example, in a backend management system developed using ThinkPHP, when the administrator completes an operation on a certain page, he needs to return to the previous page to continue the operation. In this case, you need to set a "return" button on the page. Click the button to jump to the previous page.

2. How to jump to the parent page in ThinkPHP?

  1. Set the return button in the sub-page

In order to implement the function of jumping to the parent page, you need to add a return button to the sub-page. The code for the return button is as follows:

<button onclick="javascript:history.back(-1);" class="btn btn-default">返回</button>
Copy after login

This code will add a "return" button to the page. Click the button to return to the previous page. It should be noted that -1 means returning to the previous page. If you need to return more pages, you can change the number to -2, -3, etc.

  1. Jump to the parent page after success

After completing an operation, you need to jump to the parent page, which can be achieved by adding code in the controller. The following is a code example using ThinkPHP:

public function doSomething(){
    // 这里添加操作代码,如新增记录;
    $this->success('您已经完成操作', $_SERVER["HTTP_REFERER"]);
}
Copy after login

In this code, the success method is used to prompt success information and jump to the specified page. Among them, the first parameter is the prompt information, and the second parameter is the jump url. For the requirement of jumping to the parent page, you can set the second parameter to $_SERVER["HTTP_REFERER"], which means jumping to the Referer page, that is, the previous page.

3. Notes

During use, you need to pay attention to the following points:

  1. If there is no Referer information on the previous page, the jump will fail.
  2. If there is no return button set on the previous page, you cannot return to the previous page.
  3. If you need to jump to more levels of pages, you need to modify the numeric parameters in the jump code.

4. Summary

In this article, we introduced how to use ThinkPHP to implement the function of jumping to the parent page after success. You need to add a return button to the subpage and set the jump code in the controller. Of course, you also need to pay attention to whether the page to be jumped exists and the number of levels to jump to. Mastering these skills can make us more convenient and efficient when developing web applications using ThinkPHP.

The above is the detailed content of How to jump to the parent page in thinkphp success. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template