Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6587629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:56:30+00:00 2026-05-25T16:56:30+00:00

I am a newbie with CodeIgniter (2.03), and I have the following problem: Here

  • 0

I am a newbie with CodeIgniter (2.03), and I have the following problem:

Here is my main template (view):

<?php $this->load->view('backOffice/bo_header_in'); ?>

<?php $this->load->view($bo_main_content); ?>

<?php $this->load->view('backOffice/bo_footer_in'); ?>

Here is my model:

<?php

class Back_office_users extends CI_Model 
{

  public function getAllUsers () 
  {
    $query = $this->db->query("SELECT * FROM users");

    if ($query->num_rows() > 0) {
      foreach ($query->result() as $rows) {
        $users[] = $rows;
      }
      return $users; 
    }
  }
}  

And here is my controler:

<?php

class Dashboard extends CI_Controller 
{

  public function __construct() 
  {
    parent::__construct();
    $this->is_logged_in();
  }

  public function index () 
  {   
    $this->load->model('back_office_users');
    $users['rows'] = $this->back_office_users->getAllUsers();

    $data['bo_main_content'] = "backOffice/dashboard";

    $this->load->view('backOffice/bo_template_in', $data, $users);

   // if I pass the variable like this it works just fine...
   //$this->load->view('backOffice/users', $users);
  }

  public function is_logged_in()
  {
    $is_logged_in = $this->session->userdata('is_logged_in');
    if (!isset($is_logged_in) || ($is_logged_in != true)) {
      $this->accessdenied();   
    }
  }

  public function accessdenied () 
  {    
    $data['bo_main_content'] = 'backOffice/accessdenied';
    $this->load->view('backOffice/bo_template', $data);
  }

  public function logout () 
  {    
    $this->session->sess_destroy();
    redirect('backOffice/index');
  }
}  

And the dashboard view is like this:

<?php
  print_r($users);
?> 

I am getting the following error:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: users

Filename: backOffice/dashboard.php

Line Number: 9

Can anyone shed some light how can I resolve this? I create another view without use of the template, and it print the array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:56:31+00:00Added an answer on May 25, 2026 at 4:56 pm

    You’re not passing the $users variable to the second (nested) view.

    I’d suggest adding $users to the $data array, and then in the first view pass the $users array to the embedded view. So, in your controller:

    public function index () {
    
      /* stuff... */
    
      $data['users']['rows'] = $this->back_office_users->getAllUsers();
    
      $data['bo_main_content'] = "backOffice/dashboard";
    
      /* stuff... */
    
      $this->load->view('backOffice/bo_template_in', $data);
    }
    

    Then in the main view:

    <?php $this->load->view($bo_main_content, $users); ?>
    

    Then in the dashboard view:

    <?php
      print_r($rows);
    ?>
    

    This is because in the main view, as you know, CodeIgniter transforms all elements of $data in to variables, so we’ll end up with the $users variables. $users is an array containing rows, so when we pass $users to the second view, the second view transforms all elements of $users in to view variables, hence we now have access to $row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Excuse me if this is slightly newbie. I have the main view located @
Im newbie here.I have a problem with codeigniter segment() method.I referred 6th segment of
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
Newbie here, I have a struct for a word, which contains a char array
Newbie here. The following function works fine when $color refers to an entry in
Newbie here (to C, objective-C, and iOS)... For this code in my AppDelegate.m, why
I am newbie. I have Windows XP and use the CodeIgniter framework. I wanted
I am a newbie to drupal, and have used cakephp and codeigniter frameworks earlier.
Newbie here. I'm using codeigniter and mysql How can I dynamically (number of names
Newbie question i have following function: function isadult($description) { $bad=/*comma separated bad words*/; $bad=explode(,,$bad);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.