CodeIgniter Forums

Full Version: Undefined variable:
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Atrhick[/eluser]
Can someone help me please I have no idea why the data is not being passed to my view. thak you in advance.


Model

Code:
Class Dashboard_model extends CI_Model
{
   function employees()
   {
     $this -> db -> select('id, employees_name, store_name, manager_name, email, hire_date, status, last_signin');
     $this -> db -> from('employees');
  
     $query = $this -> db -> get();
    
     if($query)
     {
   return $query->result();  
   $employees_list_data= array();
   foreach($result->result() as $employees_list_results)
   {
    $employees_list_data[] = $employees_list_results;
   }
    
     }return $employees_list_data;
    
   }
}

Controller

Code:
function employees()
{
   if($this->session->userdata('logged_in'))
   {
     $employees_list_data['employees_list_data'] = $this->Dashboard_model->employees();
     $this->view_data['employees_list_data'] = $this->Dashboard_model->employees();
  
  $this->load->view('dashboard_view', $this->view_data);
   }
}

View

Code:
<?php foreach($employees_list_data as $employees_list_show_results): ?>
     <?php foreach($employees_list_data as $employees_list_show_results): ?>
     <?php { ?>
     <tr class="odd gradeX">
     <td>&lt;?php $employees_list_show_results['employees_name']?&gt;</td>
    <td>&lt;?php $employees_list_show_results['store_name']?&gt;</td>
    <td>test_name</td>
    <td class="center"> 90% - Pass</td>
    <td class="center">
    &lt;?php $employees_list_show_results['manager_name']?&gt;</td>
     </tr>
     &lt;?php } ?&gt;
     &lt;?php endforeach; ?&gt;

El Forum

[eluser]treenef[/eluser]
I've never seen it passed in like that.

Normally, I would do:

Code:
$data['some_var'] = 'hello';

$this->load_view('someview',$data);

El Forum

[eluser]CroNiX[/eluser]
Code:
if($query)
{
   return $query->result();//Nothing below this line gets executed since you return

El Forum

[eluser]Atrhick[/eluser]
Thank you for correction i fixed those but now im having an error i cant shake again

Error
Code:
Fatal error: Call to a member function employees() on a non-object in

Model
Code:
class Dashboard_model extends CI_Model{
  
function employees()
{
    $query_str = "SELECT * "

     . " FROM employees ";

  $result = $this->db->query($query_str);
  if($result->num_rows() > 0)
  {
   $employees_list_data= array();
   foreach($result->result_array() as $employees_list_results)
   {
    $employees_list_data[] = $employees_list_results;
   }
  }
   return $employees_list_data;
}
  

function all_store_comments()
    {
     $query_str = "SELECT * FROM mail comments";
  $result = $this->db->query($query_str);
  $all_store_comments = "error I got nothing!";
  if($result->num_rows() > 0)
  {
  $all_store_comments = $result->row();
  $all_store_comments = $all_store_comments->all_store_comments;
  }
   return $all_store_comments;
}
}

Controller
Code:
session_start(); //we need to call PHP's session object to access it through CI
class Dashboard extends CI_Controller {


function index()
{
   if($this->session->userdata('logged_in'))
   {
     $session_data = $this->session->userdata('logged_in');
     $data['username'] = $session_data['username'];
  $data['id'] = $session_data['id'];
  $data['store_id'] = $session_data['store_id'];
  $data['group'] = $session_data['group'];
     $this->load->view('dashboard_view', $data);
  
  

  $employees_list_data['employees_list_data'] = $this->Dashboard_model->employees();
  $this->view_data['employees_list_data'] = $this->Dashboard_model->employees();

  
  $all_store_comments['all_store_comments'] = $this->Dashboard_model->all_store_comments();
  $this->view_data['all_store_comments'] = $this->Dashboard_model->all_store_comments();

  $this->load->view('dashboard_view', $this->view_data);

   }
   else{
     //If no session, redirect to login page
     redirect('login', 'refresh');
       }
}

function logout()
{
   $this->session->unset_userdata('logged_in');
   session_destroy();
   redirect('dashboard', 'refresh');
}

}

what you all for the awesome help thus far!

El Forum

[eluser]CroNiX[/eluser]
Did you load the dashboard_model before using it?

Why are you doing some of these things 2x?
Code:
//Is this really needed?
//$employees_list_data['employees_list_data'] = $this->Dashboard_model->employees();
$this->view_data['employees_list_data'] = $this->Dashboard_model->employees();

//Is this really needed?
//$all_store_comments['all_store_comments'] = $this->Dashboard_model->all_store_comments();
$this->view_data['all_store_comments'] = $this->Dashboard_model->all_store_comments();

El Forum

[eluser]Atrhick[/eluser]
AAAAAHHHHHHHH awesome I got it working my query have some foolishness in it. when i fixed that and everything you suggested it working perfectly. THANK YOU SO MUCH!

El Forum

[eluser]InsiteFX[/eluser]
He's trying to assign an object to an array, he should being returning result_array