Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

kohana-3

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

like image 500
boeing Avatar asked Oct 26 '12 14:10

boeing


2 Answers

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

like image 105
Jonathan Avatar answered Sep 24 '22 13:09

Jonathan


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

like image 30
Vladimir Yuldashev Avatar answered Sep 23 '22 13:09

Vladimir Yuldashev