Welcome Guest, Not a member yet? Register   Sign In
Where is the this code coming from?
#1

[eluser]matt6805[/eluser]
I have a controller passing a header template file to a view like this:
Code:
class Home extends Controller {

    function Home()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $data['title'] = 'Homepage';
                //this is the navigation
        $data['nav'] = $this->load->view("template/nav");
        $this->load->view('home', $data);
    }
}

Now this is where it get's weird. If i take <?php echo $nav; ?> OUT of the homepage view, i still see the navigation! I can't get rid of it. This is the only controller passing anything to the homepage view. Even if i create a new blank home view file, the nav is still there.

Has anyone experienced something like this?
#2

[eluser]techgnome[/eluser]
When in doubt, read the user guide: http://ellislab.com/codeigniter/user-gui...views.html ... alll the waaaay down at the bottom... where it talks about the third parameter...
Quote:There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser.

Right now you're loading and viewing it... not returning it...

-tg
#3

[eluser]matt6805[/eluser]
ahhhh, that did the trick. Thanks for the quick response Smile
#4

[eluser]Bastian Heist[/eluser]
You could also just load the nav in the views that need it, and omit it where you don't want it.
#5

[eluser]matt6805[/eluser]
Loading the Nav as needed is not the issue i was having. As the documentation says, when you pass the view as a variable rather then just loading a view, you have control over where and when it displays.

So for example:
Code:
$data['nav'] = $this->load->view("template/nav");

This will load the nav even before any HTML is written to the browser. It puts it at the very top of the page, and I have no control over it.

But, if I do this:
Code:
$data['nav'] = $this->load->view("template/nav", "", true);

Now, in my view, I have access to the contents of "template/nav" though the variable $nav. I can place it and process it anywhere i wish. That's the difference.

Regards,
Matt




Theme © iAndrew 2016 - Forum software by © MyBB