我使用的是Kohana 3.3.0,我有一个控制器,它可以将博客文章保存到数据库中,然后重定向到主页,我的代码如下:
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);
}文章保存到数据库,但重定向行给出错误:-
ErrorException [ Fatal Error ]: Call to undefined method Request::redirect()请让我知道我可以如何做重定向。
谢谢
发布于 2012-11-08 14:34:57
是的,Request::redirect已经不存在了。因此,为了便于从3.2中移植到3.3中,我扩展了Kohana_Request类并添加了重定向方法。只需在classes文件夹中创建Request.php并写入
类请求扩展Kohana_Request { /** * Kohana Redirect Method * @param string $url */公共函数重定向($url){ HTTP:: redirect($url);}}
因此您将能够同时使用Request::redirect和$this->request->redirect
发布于 2012-10-31 14:08:15
你得到这个异常是因为从Kohana3.3开始,Request不再有redirect方法。
您可以通过替换以下代码来修复示例
$this->request->redirect(self::INDEX_PAGE);
使用
HTTP::redirect(self::INDEX_PAGE);
发布于 2012-11-08 08:45:18
在您的控制器$this->redirect('page');中
https://stackoverflow.com/questions/13088601
复制相似问题