tttaaabbb tttaaabbb - 1 month ago 21
PHP Question

Redirect in OpenCart

Hi i have custom controller in admin page, and i want to redirect after some function is done. Here is my code:

public function save(){
//some operations
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".htmlentities ($this->url->link('sale/order', 'token=' . $this->session->data['token'] . '', 'SSL')));
}


as the result i see this in browser:

http://mystore/admin/index.php?route=sale/order&token=jYOWKAUGO3Xx20OcoRK00N3CFHqJJato


Instead of:

http://mystore/admin/index.php?route=sale/order&token=jYOWKAUGO3Xx20OcoRK00N3CFHqJJato


How can i fix it?

Answer

OpenCart has a built in redirect function as part of the response library.

$this->response->redirect('your url goes here', 'http status code goes here');

Comments