Welcome Guest, Not a member yet? Register   Sign In
flashdata don't work
#1

[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>&lt;?php echo form_input('nome',set_value('nome'),"id='nome'");?&gt;</td>
                        </tr>
                        <tr>
                            <td>Senha:</td>
                            <td>&lt;?php echo form_password('senha','',"id='senha'");?&gt;</td>
                        </tr>
                        <tr>
                            <td>&lt;?php echo form_submit('','Login');?&gt; </td>
                            <td> </td>
                        </tr>
                    </table>
                    &lt;?php echo form_close()?&gt;
//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


Messages In This Thread
flashdata don't work - by El Forum - 05-30-2011, 02:29 PM
flashdata don't work - by El Forum - 05-30-2011, 08:21 PM
flashdata don't work - by El Forum - 05-31-2011, 07:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB