Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect from a view in kohana

I have a function called action_reg_user which insert data into the database. I tried doing the usual:

header('Location:page/param1/param2');

But it doesn't work

<?php

if(!empty($_POST)){
    $username = $_POST['uname'];
    $pword = md5($_POST['pword']);
    print_r($_POST);

?>
<a href="reg_user/<?php echo $username; ?>/<?php echo $pword; ?>">Continue Registration</a> 

<?php } ?>
like image 333
Wern Ancheta Avatar asked Dec 07 '25 12:12

Wern Ancheta


2 Answers

Kohana doesn't generate the request headers until the final page is ready to go back to the browser. If you look in application/bootstrap.php, you'll see this near the very bottom:

echo Request::instance()
    ->execute()
    ->send_headers()
    ->response;

So what you'll want to do is get to the Request object and ask it to do the redirect for you. Usually, this should be done in your controller, not your view. In the controller, you can do $this->request->redirect('kohana/path'). If you insist on doing it in the view, you want Request::current()->redirect('kohana/path') to redirect the currently executing request in the hierarchical chain.

Be careful and notice those are NOT using URL::base in the path- Request::redirect handles that, so you just need to specify the controller/action/parameters.

like image 117
David Souther Avatar answered Dec 10 '25 02:12

David Souther


Try to use

<?php
$this->request->redirect('url/to/redirect/');

Outside actions you can use this code

<?php
Request::initial()->redirect('url');
like image 33
pzinovkin Avatar answered Dec 10 '25 01:12

pzinovkin