1

when i pass $data from controller to view, show me this error:

Severity: Notice

Message: Undefined variable: data

Filename: views/admin.php

Line Number: 10

My Controller

class Home extends CI_Controller
{

    public function index()
    {
        if($this->is_logged_in())
        {
          $data['login'] = $this->session->userdata('login');        
          $this->load->view('admin',$data['login']);
        }else
        {
          $this->load->view('login');
        }
    }

    public function login()
    {

        $this->load->model('usuario');
        $resultado = $this->usuario->validate();

        if($resultado)
        {
            $dados = array(
                    'login' => $this->input->post('login'),
                    'is_logged_in' => true
                );

            $this->session->set_userdata($dados);
            $this->index();
        }
        else
        {
            redirect('fadas');
        }


    }

    public function is_logged_in()
    {
        return $this->session->all_userdata();
    }

and my View

<!DOCTYPE html>
<html>
<head>
    <title>Admin Panel - Sistema de Controle de Indicações de Vereadores</title>
    <link rel="stylesheet" href="<?php echo asset_url();?>css/style.css">
</head>
<body>
    <header>
        <nav>
             <?php echo $data['login']; ?> </p> 
        </nav>  
    </header>
</body>
</html>

ty :)

2
  • How are you implementing sessions? Commented Mar 27, 2014 at 14:36
  • Yeap, but when you say "implementing" you say about autoload? Commented Mar 27, 2014 at 14:55

1 Answer 1

4

Just pass $data, not $data['login']. Then access it via $login.

Code below:

Controller:

$this->load->view('admin',$data);

View:

<?php echo $login ?> </p>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.