English 中文(简体)
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?

最佳回答

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 viewsscriptsindexindex.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...      
问题回答

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 );

Output buffering may be the culprit. Try:

echo  my debug output ;
flush();

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()




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签