Kohana ErrorException [ Fatal Error ]: Call to undefined method Request::redirect()

boeing picture boeing · Oct 26, 2012 · Viewed 9.1k times · Source

I'm using Kohana 3.3.0 and i have a controller which is supposed to save blog articles to a database then redirect to the homepage, my code is as follows:-

class Controller_Article extends Controller {

const INDEX_PAGE = 'index.php/article';

public function action_post() {

$article_id = $this->request->param('id');
$article = new Model_Article($article_id);
$article->values($_POST); // populate $article object from $_POST array
$article->save(); // saves article to database

$this->request->redirect(self::INDEX_PAGE);
}

The article saves to database but the redirect line gives the error:-

ErrorException [ Fatal Error ]: Call to undefined method Request::redirect()

Please let me know how i can do the redirect.

Thanks

Answer

Jonathan picture Jonathan · Oct 31, 2012

You're getting the Exception because as of Kohana 3.3, Request no longer has the method redirect.

You can fix your example by replacing

$this->request->redirect(self::INDEX_PAGE);

with

HTTP::redirect(self::INDEX_PAGE);