Welcome Guest, Not a member yet? Register   Sign In
To redirect or return?
#1

[eluser]Unknown[/eluser]
I am wondering if it is better in general to redirect or to return the next page.

Example Fake Controller:

Code:
...
function index()
{
  ...
}

function form($param = FALSE)
{
  if($param === FALSE)
  {
    send_message('Link Error');
    return $this->index();
    OR
    redirect('controller/index');
  }
  $this->show_form;
  if($form_validated)
  {
    return $this->thanks();
    OR
    redirect('controller/thanks');
  }
  $this->template->render();
}

function thanks()
{
  ...
}
...

Redirect has the advantage of keeping your url straight, but return saves hassle with changing roots, and makes passing data much easier.

Thoughts?




Theme © iAndrew 2016 - Forum software by © MyBB