CodeIgniter Forums
reusing common methods + redirect to current page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: reusing common methods + redirect to current page (/showthread.php?tid=9958)

Pages: 1 2


reusing common methods + redirect to current page - El Forum - 01-19-2009

[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.


reusing common methods + redirect to current page - El Forum - 09-17-2010

[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/