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.
#12

[eluser]brettalton[/eluser]
This is how I redirect to current page and I think the solution is quite elegant: http://ellislab.com/forums/viewreply/801348/




Theme © iAndrew 2016 - Forum software by © MyBB