![]() |
Am I Loading this View wrong? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Am I Loading this View wrong? (/showthread.php?tid=54004) |
Am I Loading this View wrong? - El Forum - 08-17-2012 [eluser]Kraig[/eluser] This is my errior - Message: Undefined variable: user_info On my home page I have a Views template that looks like this: Code: <?php $this->load->view('includes/header'); ?> 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 Code: class TopMembers extends CI_Controller { And here is my topMembers View Code: <?php Am I Loading this View wrong? - El Forum - 08-17-2012 [eluser]CroNiX[/eluser] You're loading the topMembers view 2x, and the first time you're not sending data to it so $user_info comes up undefined. Am I Loading this View wrong? - El Forum - 08-17-2012 [eluser]Kraig[/eluser] 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? Am I Loading this View wrong? - El Forum - 08-17-2012 [eluser]Kraig[/eluser] 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? Am I Loading this View wrong? - El Forum - 08-17-2012 [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: Code: class Common { 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: Code: $this->load->library('common'); |