Welcome Guest, Not a member yet? Register   Sign In
reusing common methods + redirect to current page
#11

[eluser]fchristant[/eluser]
I'm also using the HTTP Referer. I have a basecontroller class which extends all my controllers. It has this method:

Code:
function pagerefresh() {
   // redirects the page to the current page
   header('location:'.$_SERVER['HTTP_REFERER']);
   flush();
   exit();
}

Next I can call $this->pagerefresh() from my controllers. I use this often in combination with a message, for example:

Code:
if ($userid == $imagedata['user_id']) {
   $this->session->set_flashdata('pagemessage', "You cannot vote on your own images!");
   $this->pagerefresh();
}

Some of my views have this code to display the message:

Code:
<?php
$message = $this->session->flashdata('pagemessage');
if ($message) { ?>
<p class="msg">&lt;?= $message ?&gt;</p>
&lt;?php } ?&gt;

I use this mechanism to redirect the user to the current page whilst also displaying a message. I like this because there is no javascript reliance. The HTTP Referer is a dependency, but it is one I have control over, I also rely on it for Cancel buttons.


Messages In This Thread
reusing common methods + redirect to current page - by El Forum - 07-14-2008, 12:32 PM
reusing common methods + redirect to current page - by El Forum - 07-15-2008, 05:25 AM
reusing common methods + redirect to current page - by El Forum - 07-15-2008, 06:05 PM
reusing common methods + redirect to current page - by El Forum - 07-15-2008, 08:37 PM
reusing common methods + redirect to current page - by El Forum - 07-16-2008, 12:22 PM
reusing common methods + redirect to current page - by El Forum - 07-16-2008, 12:55 PM
reusing common methods + redirect to current page - by El Forum - 07-21-2008, 04:40 PM
reusing common methods + redirect to current page - by El Forum - 07-21-2008, 05:03 PM
reusing common methods + redirect to current page - by El Forum - 07-21-2008, 05:08 PM
reusing common methods + redirect to current page - by El Forum - 07-31-2008, 02:39 PM
reusing common methods + redirect to current page - by El Forum - 01-19-2009, 01:29 PM
reusing common methods + redirect to current page - by El Forum - 09-17-2010, 10:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB