5

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

boeing
  • 302
  • 7
  • 19

4 Answers4

8

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

Jonathan
  • 1,089
  • 1
  • 7
  • 10
5

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

Mahmoud Gamal
  • 322
  • 4
  • 10
4

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

UAMoto
  • 271
  • 3
  • 8
1

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

Andrew Koper
  • 6,481
  • 6
  • 42
  • 50