• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
echo statements rendering out of order with multiple views? CodeIgniter newbie

Hi I'm new to codeigniter and I have been trying to to make a main controller and instantiate other controllers like a menu controller, and then display the views, but the output seems to go out of order. Mainly echo statements seem to come out first.
Anyone know why echo statements are rendered first?

In my main controller I have:

    $MainMenu = new Menu();

Here's the code for showMenu, where the echo statements are.

function showMenu(){
             echo "fun in the sun";
             echo $this->calendar->generate(); echo seems to render wrong time
            $menuItems['items'] =  this->menu_model->getMenuItems();        


I thought I would get

header view
fun in the sun

menu view

instead I get:

fun in the sun

header view
menu view

the two echo statements output first even though they are called second.

Any help is appreciated.
Thanks so much.

[eluser]Thorpe Obazee[/eluser]
You should be loading libraries like:


Anyway, use the views to output anything to the browser.

The reason for this, is that an echo is sent directly to the browser, but when you load a view, it gets buffered until you read the end of that controller function, then all the views which have been buffered get written to the screen at once

Output should only be sent from a view, unless of course you're debugging.

Thanks all. Super fast response!

Ya I woke up this morning and realized that I was calling the echo statements in my menu controller not the view, and thus it wasn't being handled as part of the view. (Good to know the view buffer stream is cleared at the end of the controller function).

I passed the calendar generate() output as a string to the view and it works perfectly Smile

Thanks again.

Oh, and welcome to the CodeIgniter forums. Big Grin

[eluser]Thorpe Obazee[/eluser]
[quote author="JojoBelmonte" date="1241476178"]Thanks all. Super fast response![/quote]


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.