Zend MVC - 我回显一些测试调试输出,但它似乎被抑制并且不显示

发布于 2024-08-17 02:36:10 字数 313 浏览 11 评论 0原文

我正在开发 Zend MVC 应用程序。

有时我喜欢回显一些文本只是为了快速而肮脏的调试。例如,

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

我可以在引导程序中回显“调试文本”>但是,当文本在我的模型或控制器中回显时,它不会在输出中呈现。

我正在使用 Zend 1.9.5 并使用 Zend Layout 和 MVC


是否有某个设置可以抑制所有“非视图脚本渲染”输出?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

沒落の蓅哖 2024-08-24 02:36:10

您还可以使用 die() 而不是 echo :) 它会起作用。或者使用 Zend_Log 和输出编写器,如下所示:

$writer = new Zend_Log_Writer_Stream('php://output');

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');
地狱即天堂 2024-08-24 02:36:10

输出缓冲可能是罪魁祸首。尝试:

echo 'my debug output';
flush();

Output buffering may be the culprit. Try:

echo 'my debug output';
flush();
茶色山野 2024-08-24 02:36:10

如果打开了 viewRendering,它可能会寻找要渲染的视图/脚本/,并且可能不会显示您的 echo 语句。

您可以尝试关闭给定控制器的 viewRendering 并查看是否有帮助。

viewRenderer->setNoRender()

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()
断肠人 2024-08-24 02:36:10

我回答这个问题是因为 10 个月后我又回到了同样的代码,它再次让我困惑。

我处于默认模块、索引控制器和索引操作的上下文中。

我想回显一些简单的文本,作为查看代码中发生的情况的快速方法:

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

问题是 - 回显的文本没有显示。

它在其他控制器中有效,但在这个控制器中无效。这让我发疯。

现在——我已经解决了这个问题。

我为这个特定的控制操作使用了特殊的布局......“主页布局”。

在我的主页布局中,我没有渲染任何视图脚本。所有的内容和设计都在布局中。由于主页是一个特殊的、独特的页面,因此无需分成两步视图。因此,我没有理由需要视图脚本。但是,我确实创建了一个“views\scripts\index\index.phtml”来防止 ZF 抱怨。然而,我没有在我的布局中渲染它 - 因为不需要它。

任何回显的输出都会被捕获到 layout()->content 中(由布局从“默认”响应段自动分配)。因为我没有回显该片段,所以它的表现就好像回显的文本被抑制了。

为了解决这个问题,我只需确保我正在回显内容片段。

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

,我的调试文本也被回显...将呈现为:

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

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...      
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文