Search code examples
phpmodel-view-controllerzend-frameworkechozend-layout

Zend MVC - I echo some test debug output but it seems to be suppresed and does not show


I am developing a Zend MVC application.

Sometimes I like to echo some text just for quick and dirty debugging. e.g

<?php
class MyClass {}
echo('hello world - yes this script is included');

I can echo 'debug-text' in my bootstrap> But, when text is echoed in my model or controllers it is NOT being rendered in the output.

I am using Zend 1.9.5 and using Zend Layout with MVC


Is there a setting somewhere that is suppressing all ''non-view script rendered'' output?


Solution

  • I am answering this question because I came back to the same code , 10 months later , and it confused me again.

    I was in the context of a Default Module, Index Controller, and Index Action.

    I wanted to echo some simple text as a quick way to see what was happening in the code:

    class IndexController extends Zend_Controller_Action
     {
    
     public function indexAction()
      {
      //home page
      echo '<h1>hello world</h1>';
    
      //set the special home page layout
      $this->_helper->layout()->setLayout('home-page');
      }
    

    Trouble was - the echoed text was just not showing up.

    It worked in other controllers , but not this one. It was driving me crazy.

    Now - I've worked out the problem.

    I was using a special layout for this particular control action... a 'home page layout'.

    In my home page layout I was not rendering any view script. All the content and design was in the layout. Because the home page is a special , unique page, there was no need to separate into a two step view. For this reason I had no reason to need a view script. But, I did create a 'views\scripts\index\index.phtml' to keep ZF from complaining. I did not however, render it in my layout - cos it was not needed.

    Any echoed output is captured into the layout()->content (automatically assigned by the layout from the 'default' response segment). Because I was not echoing out that segment, it behaved as if the echoed text was being suppressed.

    To solve the problem , i simply had to ensure that i was echoing out the content segment.

    i.e.

    <html>
    <head>
    ...
    </head>
    <body>
    ... my home page html...
    <?php echo $this->layout()->content ?>
    ... my home page html...
    </body>
    </html>
    

    which, with my debug text being echoed too... would render as:

    ... my home page html...
    <h1>hello world</h1>
    ... my home page html...