重定向到上一页时如何发送变量数据 [英] How to send variable data when redirecting to previous page
问题描述
完成特定任务后,我使用以下代码将用户重定向到上一页。
I am using the following codes to redirect my user to previous page after a particular task is done.
if (isset($_SERVER['HTTP_REFERER']))
{
$this->session->set_userdata('previous_page', $_SERVER['HTTP_REFERER']);
}
else
{
$this->session->set_userdata('previous_page', base_url());
}
我在控制器中使用以上代码,在另一个控制器中使用以下代码。 。
The above code I use in a controller and the following code in another controller..
.... some other stuffs... I am updating database values here....
$this->db->where('t_expenseid', $t_expenseid);
query=$this->db->update('teacherexpense', $data);
redirect($this->session->userdata('previous_page'));
上面的代码工作正常,但我面临的问题是我想发送成功消息重定向,以便在上一页加载时弹出一条成功消息(我已经为此使用了jquery)。为此,我在重定向上方添加了以下代码,但我不知道如何与重定向一起发送$ data或消息。如果我能够发送它,如何在上一页的控制器中检索值。
The above code is working fine but the problem I am facing is I want to send a success message with the redirect so that when the previous page loads a success message pops up (I already have jquery for that). And for this I added the following code above the redirect, but I don't know how to send the $data or the message along with the redirect. And if I am able send it how to retrieve the value in the controller of the previous page.
$data['msg']='Information Has been Successfully Inserted';
能否请您告诉我如何发送然后取回它?
Could you please tell me how to send it and then retrieve it?
谢谢:)
推荐答案
您可以使用CI的set_flashdata。该消息只能使用一次刷新页面消息变为空白后。
You can use set_flashdata of CI.You can use only once that message after refresh page message goes blank.
$this->session->set_flashdata('message', 'Authentication failed');
redirect(site_url('message/index/'), 'refresh');
在该页面上,您可以通过
And on that page you can catch this message by
$message = $this->session->flashdata('message').
这篇关于重定向到上一页时如何发送变量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!