重定向到上一页时如何发送变量数据

发布于 2024-12-22 00:09:15 字数 919 浏览 2 评论 0原文

在完成特定任务后,我使用以下代码将用户重定向到上一页。

        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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

删除会话 2024-12-29 00:09:15

您可以使用CI的set_flashdata。您只能使用刷新页面消息后该消息变为空白的一次。

  $this->session->set_flashdata('message', 'Authentication failed');

  redirect(site_url('message/index/'), 'refresh'); 

在该页面上,您可以通过以下方式捕获此消息

$message = $this->session->flashdata('message').

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').
榕城若虚 2024-12-29 00:09:15

考虑使用 flashdata,它通常用于您想要重定向到某个页面并且显示一条消息。请记住,该消息只会显示一次。如果用户刷新页面,该消息就会消失。

以下是如何使用它:

$this->db->where('t_expenseid', $t_expenseid);
query = $this->db->update('teacherexpense', $data);

// set flashdata
$this->session->set_flashdata('message', 'Information Has been Successfully Inserted');

redirect($this->session->userdata('previous_page'));

然后在“上一页”中,您可以检查消息并显示它(如果存在):

// get flashdata
$message = $this->session->flashdata('message');

if ($message) {
    // pass message to view, etc...
}

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:

$this->db->where('t_expenseid', $t_expenseid);
query = $this->db->update('teacherexpense', $data);

// set flashdata
$this->session->set_flashdata('message', 'Information Has been Successfully Inserted');

redirect($this->session->userdata('previous_page'));

Then in the "previous page" you could check for a message and display it if it exists:

// get flashdata
$message = $this->session->flashdata('message');

if ($message) {
    // pass message to view, etc...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文