Kohana redirect

2019-07-24 02:23发布

问题:

After a form-submit in Kohana, I want the user to go back to the homepage. Is it correct to use a redirect for this?

public function action_edit($id)
{
    if (!empty($post))
    {
        if ($post->validate())
        {
            $this->request->redirect(Route::get('admin')->uri(array('action' => 'list')));

        }
    }
}

Thanks in advance!

回答1:

Sometimes $this->request->uri($params) (instead of Route::get()->uri()) maybe useful. For example, when you want to use current controller (redirect to another action) or the same route. It will use route params from current request by default.



回答2:

The redirecting part is indeed correct. The validation part is missing a few lines.