boeing
boeing

Reputation: 302

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

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

Upvotes: 5

Views: 9351

Answers (4)

Vladimir Yuldashev
Vladimir Yuldashev

Reputation: 199

Yeah, Request::redirect is not longer exists. So in order to easily to move from 3.2 to 3.3 I extented Kohana_Request class and added redirect method. Just create Request.php in classes folder and write

class Request extends Kohana_Request {

    /**
     * Kohana Redirect Method
     * @param string $url
     */
    public function redirect($url) {
       HTTP::redirect($url);
    }

}

So you will be able to use both Request::redirect and $this->request->redirect

Upvotes: 5

Andrew Koper
Andrew Koper

Reputation: 7191

$this->redirect('article/index');

Upvotes: 1

UAMoto
UAMoto

Reputation: 271

in your controller $this->redirect('page');

Upvotes: 4

Jonathan
Jonathan

Reputation: 1089

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);

Upvotes: 8

Related Questions