我创建了一个 MY_Controller 类来检查会话。
我的 LoginController 正在检查用户信息,如果没问题,我将用户重定向到 PainelController。我使用重定向,所以我的 url 将使用 /localhost/painel 而不是 /localhost/session/login 刷新
问题是当我使用重定向时,我无法访问我的会话,只能使用 load->view。
有解决方法吗?
提前感谢您的帮助。
PS:我使用 .htaccess,在CI Wiki上找到的
编辑
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
if(!$this->session->userdata('usuario')) {
redirect('login');
}
}
}
登录片段:扩展 CI_Controller
if( $rs )
{
$this->session->set_userdata('usuario', $usuario);//usuario is a object
//$this->load->view('painel');//it works
redirect('painel', 'location');//it doesn't
}
else
{
$this->load->view('login', $data = array('mensagem'=>'Usuário ou senha inválidos.'));
}
--
我的面板视图
echo $this->session->userdata('usuario')->usuario_nome; //it works
only if I load->view('painel')
即使我尝试在我的 PainelController(扩展 MY_Controller)上访问此会话值,它也不起作用,会说:
Message: main() [function.main]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Usuario" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition