Welcome Guest, Not a member yet? Register   Sign In
Am I Loading this View wrong?

This is my errior - Message: Undefined variable: user_info
On my home page I have a Views template that looks like this:
<?php $this->load->view('includes/header'); ?>

<?php $this->load->view('includes/topMembers'); ?>

<?php $this->load->view('includes/news'); ?>

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

<?php $this->load->view('includes/footer'); ?>

Now I'm trying to figure out how to create a topMembers controller that way I can load a model and get some topMembers information. Keep in mind that the topMember view is loaded onto my home page. I do have a topMembers controller, but for some reason when I "reload" the topMembers view with a variable it is not working. Am I going about this wrong? Here's my topMembers controller
class TopMembers extends CI_Controller {

function index()
  // Grabbing all the files associated with the current user
  $q = $this->membership_model->user_info();
  $data['user_info'] = $q;
  $this->load->view('includes/topMembers', $data);



And here is my topMembers View
$user = array();
foreach ($user_info as $value)
  $user[] = $value['first_name'];

//HTML below

You're loading the topMembers view 2x, and the first time you're not sending data to it so $user_info comes up undefined.

So which load do I need to do? I want topMembers to be loaded onto the home page, and home page loads that template. Do I need to move my query over to the home pages controller in order to use it?

I did it through my home pages controller...seeing how that's the page that is loaded, and topMembers a subview. It works now, but is there a way of doing it the other way?

[eluser]Oscar Dias[/eluser]
If your views inside /include aren't going to change, you can create a library that loads that for you. Something like this:
class Common {
    function show($view, $data = array())
        // Get current CI Instance
        $CI = & get_instance();
        // Grabbing all the files associated with the current user
        $q = $CI->membership_model->user_info();
        $data_topMembers['user_info'] = $q;

        // Load include views
        $CI->load->view('includes/topMembers', $data_topMembers);
        $CI->load->view($view, $data);

Depending on your needs this might be a good solution. You can pass additional parameters, for example SEO information for your header view... Then in your controller you do:

Theme © iAndrew 2016 - Forum software by © MyBB