Zend Framework output rendering order

I'm trying to understand the workflow of Zend application. For tests i've defined:

Controller - IndexController.php:

public function preDispatch() {
        error_log('IndexController::preDispatch');
        echo 'IndexController::preDispatch <br />'; }

public function init() {       
        error_log('IndexController::init');
        echo 'IndexController::init <br />'; }

public function indexAction() {        
        error_log('IndexController::indexAction');
        echo 'IndexController::indexAction <br />'; }

View script - index.phtml:

<?php
    echo'index view script - echo';
    $this->title = "ZF Tutorial";
    $this->headTitle($this->title); ?>
<h3>index view script - content</h3> 

Layout script - layout.phtml

...
<body>
    <div id="content">  
    <?php 
    error_log('Layout1');
    echo $this->layout()->content ?>
        <h1>
            <?php 
            error_log('Layout2');
            echo $this->escape($this->title); ?>            
        </h1>
    </div>
</body>
...

And here is my confusion. The order of error_log output is different from i've got in the browser.

error_log output (the expected order):

  • IndexController::init
  • IndexController::preDispatch
  • IndexController::indexAction
  • Layout1
  • Layout2

the browser output:

  • IndexController::init
  • index view script - echo
  • index view script - content
  • IndexController::preDispatch
  • IndexController::indexAction
  • ZF Tutorial

Why do the output in controller is rendered AFTER view script? Is the echo results from preDispatch & indexAction buffered somehow to output view script content first?

Answers


Yes, any output during the dispatch process is captured by an output buffer and appended to the response. This might seem confusing, but you aren't supposed to output things in a controller directly (but if you did you would still want to see it). Your error_log list shows the order these things are executed which is all that really matters.


Need Your Help

When we create Button frame within for loop then now we want to remove or clean button frame then how can do this?

iphone ios objective-c

When we create Button frame within for loop then now we want to remove or clean button frame then how can do this ?

JayData vs Upshot (crossplatform HTML5 app)

html5 cross-platform hybrid upshot jaydata

I'm just in the planning phase of developing my iPhone/iPad/Android app.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.