kohana-3

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


Solution

  • 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