0
votes

I am developing a web application with codeigniter. I have a main screen which loads three views as follows: 1)header 2)main screen 3)footer

the 'main_screen' view loads another view called 'login' here is the code

<?php
    if($logged == null){
        $CI = &get_instance();
        $CI->load->view('login');
    }else{
        echo $logged;
    $CI = &get_instance();
    $CI->load->view('login');
    }
  ?>

the variable $logged is actually a data sent by a controller, when I first time loads the page it gives error 'Undefined, variable', but when i login it doesn't, here is the code.

 if($loginSucessfull){
      $data['logged'] ='<div class="success">Login Sucessfull</div>';
        $this->load->view('header');
       //here I am sending data to the 'menu_screen'
        $this->load->view('menu_screen',$data);
        $this->load->view('footer');

    } else {
        $data['logged'] = '<div class="alert">Sorry the username or password is incorrect</div>';
        $this->load->view('header');
      //here again I am sending the data
        $this->load->view('menu_screen',$data);
        $this->load->view('footer');
    }

What I am trying to do is, if the user is sucessfully logged in show the sucessfull message else show the error and the login form as well. please help me how to fix this.

2

2 Answers

0
votes

$logged isn't null. You get the error because the variable does not exist.

You have to set $logged to something before the main_screen page loads.

0
votes

I don't know whether it works or not. Just try:

data = array();
$data['logged'] = 'something that you want to assign';