1

This is kinda a noob question. I have a controller that update record from a database, and then display the main page. In the update method,

function update() {
  $row = $this->db->update($tablename, $data);
  if($row == 1) {
    $this->index();
  }
}

In this case, the view goes back to the index page, but the url is still localhost/controller/update. Should I use redirect instead?

function update() {
  $row = $this->db->update($tablename, $data);
  if($row == 1) {
    redirect(controller/index);
  }
}

Which method is the correct way of redirecting pages? Thank you.

1
  • well, the function name tells everything: "redirect" is the best method to...redirect ;) Commented Jun 7, 2012 at 17:38

1 Answer 1

3

I'd suggest using the redirect method. That way they can't accidently reload the page, and re-edit the row (I guess they could hit back...).

P.S. You need quotes around controller/index.

redirect('controller/index');
Sign up to request clarification or add additional context in comments.

2 Comments

If I want to pass message, such as 'row has been successfully updated', I pass it using uri segment?
@Eric: That's one way. Personally, I like flashdata. Before redirecting: $this->session->set_flashdata('message', 'Row Updated');. Then on the new page $this->session->flashdata('message');.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.