重定向到上一页时如何发送变量数据
在完成特定任务后,我使用以下代码将用户重定向到上一页。
if (isset($_SERVER['HTTP_REFERER']))
{
$this->session->set_userdata('previous_page', $_SERVER['HTTP_REFERER']);
}
else
{
$this->session->set_userdata('previous_page', base_url());
}
我在一个控制器中使用上面的代码,在另一个控制器中使用以下代码。
.... 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 或消息。如果我能够发送它如何检索上一页控制器中的值。
$data['msg']='Information Has been Successfully Inserted';
您能告诉我如何发送并检索它吗?
谢谢 :)
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'));
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?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用CI的set_flashdata。您只能使用刷新页面消息后该消息变为空白的一次。
在该页面上,您可以通过以下方式捕获此消息
You can use set_flashdata of CI.You can use only once that message after refresh page message goes blank.
And on that page you can catch this message by
考虑使用 flashdata,它通常用于您想要重定向到某个页面并且显示一条消息。请记住,该消息只会显示一次。如果用户刷新页面,该消息就会消失。
以下是如何使用它:
然后在“上一页”中,您可以检查消息并显示它(如果存在):
Consider using flashdata, which is generally used in situations where you want to redirect to a page and display a message. Keep in mind that the message will only be displayed once. If the user refreshes the page the message will disappear.
Here is how you would use it:
Then in the "previous page" you could check for a message and display it if it exists: