Welcome Guest, Not a member yet? Register   Sign In
load problem?
#1

[eluser]Avril[/eluser]
Hello,

I'm having a problem with some variables that I want to print out on a header page.
Let's say that I have a header.php and a index.php in my views folder.

The header.php is included in the index.php, I've done this to re-use the same header file for other pages. The data that will be printed out in the header.php comes from the nav.php in the controller folder.

Here's the code in the nav.php file:

Code:
<?php

class Nav extends Controller {

    function header(){
        
        $this->load->model('admin_model');
        $data['link'] = $this->admin_model->navigation();
        $this->load->view('header', $data);
        
    }
    
}

And here's the code in the header.php file:

Code:
<?php echo doctype('html4-strict') ?>

<html >

<head>

    <title>DJ Luno Maro</title>
    
    <!-- Start Stylesheets -->
    <link rel="stylesheet" href="<?php echo base_url() ?>styles/styles.css" type="text/css" />
    <!--[if IE 7]>
    <link rel="stylesheet" href="<?php echo base_url() ?>styles/ie7.css" type="text/css" />
    <![endif]--&gt;
    &lt;!--[if IE 8]>
    &lt;link rel="stylesheet" href="&lt;?php echo base_url() ?&gt;styles/ie8.css" type="text/css" /&gt;
    <![endif]--&gt;
    &lt;!-- // End Stylesheets --&gt;
    
    
    &lt;!-- Start Javascripts --&gt;
    [removed][removed]
    [removed][removed]
    [removed][removed]
    [removed][removed]
    [removed][removed]
    &lt;!-- // End Javascripts --&gt;

&lt;/head&gt;

&lt;body&gt;

    <div id="main">
    
        <div class="left_swirl"></div>
        
        <div class="star_burst">
        
            <div class="logo"></div>&lt;!-- // logo div --&gt;
            <div class="logo-tail"></div>&lt;!-- // logo-tail div --&gt;
        
        </div>&lt;!-- // star_burst div --&gt;
        
        <div class="right_swirl"></div>
        
        <div id="main_content" class="clearfix">
        
            &lt;?php print_r($link) ?&gt;
        
            <ul id="nav" class="horizontal-list clearfix">
            
                <li class="current"><a href="#">HOME</a></li>
                <li><a href="#">BIOGRAPHY</a></li>
                <li><a href="#">MIXES</a></li>
                <li><a href="#">LINKS</a></li>
                <li><a href="#">CONTACT</a></li>
            
            </ul>&lt;!-- // nav ul --&gt;

When I load the page I get this error:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: link

Filename: views/header.php

Line Number: 47

Not sure what I'm doing wrong here?
#2

[eluser]Ephyzy[/eluser]
Hey Im a n00b myself but I think I see the problem. You are not meant to "include" the header.php in index.php !!!

The Nav controller sends your nav link data "$link" to a VIEW called header, which of course does not exist, or is in the wrong location.

Move the header.php into ur view folder and remove the include from index.php

As for how to use the header.php in multiple views, read this CI forum thread:
http://ellislab.com/forums/viewthread/169208/

Hint: You almost NEVER need to edit the index.php file in CI.

Cheers...




Theme © iAndrew 2016 - Forum software by © MyBB