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?
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>
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.
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"]); }
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:
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!