[eluser]Unknown[/eluser]
Hi!
I've a litte trouble with set_flashdata/flashdata function that maybe you guys can help me. After set the userdatas, I verify if the user is disabled (deleted) in the Admin controller. If it's "Desativado", then I redirect to the login function, in the Principal controller, where I show the flashdata.
here is my code
Admin Controller
Code:
class Admin extends CI_Controller {
function _logado(){
$nivel = $this->session->userdata('nivel');
if (!isset($nivel)){
return false;
}
if ($nivel == 'Desativado'){
return false;
}
return true;
}
public function __construct() {
parent::__construct();
if (!$this->_logado()){
$this->session->set_flashdata('failed', 'Você não tem acesso a essa área');
redirect('login', 'refresh');
}
}
function index(){
if ($this->_logado())
$this->load->view('admin/index');
}
Principal Controller
Code:
class Principal extends CI_Controller {
public function __construct(){
parent::__construct();
}
public function index()
{
$this->load->view('principal/index');
}
function login(){
$this->load->view('admin/login');
}
//further code
Login view
Code:
//further html code
<?php echo $this->session->flashdata('failed');?>
<table>
<tr>
<td>Login:</td>
<td><?php echo form_input('nome',set_value('nome'),"id='nome'");?></td>
</tr>
<tr>
<td>Senha:</td>
<td><?php echo form_password('senha','',"id='senha'");?></td>
</tr>
<tr>
<td><?php echo form_submit('','Login');?> </td>
<td> </td>
</tr>
</table>
<?php echo form_close()?>
//further html code
The session class is autoloaded. 'login' is in the routes.php file ($route['login'] = "principal/login";).
I've tried to show the flashdata after I've set it, but nothing appeared. What am I doing wrong??
I'm using the version 2.0.2 of CI, Apache 2.2.11 and PHP 5.3.0
Thanks in advance