1

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?

JW.
  • 4,821
  • 5
  • 43
  • 60
  • are you actually including the MyClass file into your application, or instantiating MyClass() as an object anywhere in your application? – Mark Jan 08 '10 at 16:03
  • I'm doing both. Including the file first and refreshing a page to see if the text is output and sometimes also instantiating the class as an object. It was really just an example of 'some debug text'. – JW. Jan 10 '10 at 16:14
  • to all answerers so far - thanks i will try these suggestions out – JW. Jan 10 '10 at 16:17

4 Answers4

1

You can also use die() instead of echo :) it will work. Or use Zend_Log and output writer like this:

$writer = new Zend_Log_Writer_Stream('php://output');
Tomáš Fejfar
  • 11,129
  • 8
  • 54
  • 82
  • yep die() does the trick and makes me remove it pretty quickly too. – JW. Jan 22 '10 at 12:12
  • but it's better to have a function that takes the callstact and fetches the location where the "die" was called (should be level-2) and then echo something like `Form_Contact::init(): line 56: NULL` Which makes it easier to remove these calls when doing some extended debuging without debuger :) – Tomáš Fejfar Jan 22 '10 at 14:44
1

Output buffering may be the culprit. Try:

echo 'my debug output';
flush();
Mike B
  • 31,886
  • 13
  • 87
  • 111
0

If viewRendering is turned on, it's probably looking for the view/scripts/ to render and possibly not displaying your echo statements.

You could try to turn viewRendering off the given controller and see if that helps.

viewRenderer->setNoRender()
mr-sk
  • 13,174
  • 11
  • 66
  • 101
0

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...      
JW.
  • 4,821
  • 5
  • 43
  • 60