Welcome Guest, Not a member yet? Register   Sign In
Bug in CI2 view logic, or my logic?
#1

[eluser]dallen33[/eluser]
I'm using the latest CodeIgniter 2 and I'm loading some views in a relatively simple manner:

Code:
function index()
    {
        $data['stylesheet']    = (eregi("iPhone", $_SERVER['HTTP_USER_AGENT'])) ? 'iphone.css' : 'screen.css';
        $data['header']        = $this->load->view('header', $data);
        $data['toolbar']    = $this->load->view('toolbar_home');
        $data['weather']    = $this->weather->display_weather('edmonton');
        $data['footer']        = $this->load->view('footer');
        $this->load->view('home', $data);
    }

And here's my HTML view:

Code:
<?php echo $header; ?>

<?php echo $toolbar; ?>

<div id="header">
    <div class="home"></div>
</div>

<div id="weather">
    <div class="wrap">
        <div class="col1">
            CURRENT CONDITIONS
        </div>
        <div class="col2">
            &lt;?php echo $weather; ?&gt;
        </div>
    </div>
</div>

<div id="content">
    <div class="wrap">
        <ul>
            <li><a href="test.html">Latest Festival &amp; Game News</a></li>
            <li><a href="test.html">Daily Events</a></li>
            <li><a href="test.html">Hospitality Rooms</a></li>
            <li><a href="test.html">Maps</a></li>
            <li><a href="test.html">How to get around</a></li>
            <li><a href="test.html">Photo galleries</a></li>
            <li><a href="test.html">Talk to us!</a></li>
        </ul>
    </div>
</div>

&lt;?php echo $footer; ?&gt;

Problem is, my $footer is actually appearing after $toolbar. So my generated HTML looks like this:

Code:
<div id="toolbar">
    <div class="col1">
        <div class="logo"></div>
    </div>
    <div class="col2">
        <a href="http://www.example.com/" class="button"></a>
    </div>
</div>&lt;/body&gt;
&lt;/html&gt;

<div id="header">
    <div class="home"></div>
</div>

Any idea why this is happening?
#2

[eluser]dallen33[/eluser]
Not sure why this works (anyone care to explain?), but I altered the code:

Code:
$data['footer']        = $this->load->view('footer', '', TRUE);

Now it works as it should (displaying on the bottom of the page). So what was the issue?
#3

[eluser]bl00dshooter[/eluser]
bugs go here: http://ellislab.com/forums/viewforum/51/
#4

[eluser]Bart Mebane[/eluser]
@dallen33: Without the third parameter, load->view echoes the html immediately instead of returning it. If you set the third parameter to TRUE, it returns the html as a string without echoing it.
#5

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...views.html

Quote:Returning views as data

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. This can be useful if you want to process the data in some way. If you set the parameter to true (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:

Code:
$string = $this->load->view('myfile', '', true);




Theme © iAndrew 2016 - Forum software by © MyBB