0
我的基本控制器有以下几点:的Kohana 3:设置/获取提示信息和会话
protected $session;
public function before()
{
parent::before();
$this->session = Session::instance();
}
扩展该控制器和当用户试图登录我重定向用户,如果用户名/密码一直没有填入:
if($this->request->method() == Request::POST)
{
$username = $this->request->post('username');
$password = $this->request->post('password');
if(strlen($username) == 0)
{
$this->session->set('error', 'Please enter a Username');
Request::current()->redirect('user/login');
}
if(strlen($password) == 0)
{
$this->session->set('error', 'Please enter a Password');
Request::current()->redirect('user/login');
}
}
$error = $this->session->get_once('error');
$view = View::factory('user/login');
$view->bind('title', $title);
$view->bind('error', $error);
echo $view->render();
但是,$ error参数在返回时始终为NULL。这是因为会话通过基本控制器重置吗?我该怎么做才能避免这种情况?
@martino感谢,但我更愿意理解为什么会话变量被重置,如果有一种变通方法。 – xylar 2012-02-09 11:44:19
尝试仅删除2个重定向,然后看看会发生什么 – matino 2012-02-09 12:15:20
谢谢你的工作。如果重定向到不同的控制器,会话值将保留,我需要更改哪些内容? – xylar 2012-02-10 09:36:37