Zend MVC - 我回显一些测试调试输出,但它似乎被抑制并且不显示
我正在开发 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您还可以使用 die() 而不是 echo :) 它会起作用。或者使用 Zend_Log 和输出编写器,如下所示:
You can also use die() instead of echo :) it will work. Or use Zend_Log and output writer like this:
输出缓冲可能是罪魁祸首。尝试:
Output buffering may be the culprit. Try:
如果打开了 viewRendering,它可能会寻找要渲染的视图/脚本/,并且可能不会显示您的 echo 语句。
您可以尝试关闭给定控制器的 viewRendering 并查看是否有帮助。
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.
我回答这个问题是因为 10 个月后我又回到了同样的代码,它再次让我困惑。
我处于默认模块、索引控制器和索引操作的上下文中。
我想回显一些简单的文本,作为查看代码中发生的情况的快速方法:
问题是 - 回显的文本没有显示。
它在其他控制器中有效,但在这个控制器中无效。这让我发疯。
现在——我已经解决了这个问题。
我为这个特定的控制操作使用了特殊的布局......“主页布局”。
在我的主页布局中,我没有渲染任何视图脚本。所有的内容和设计都在布局中。由于主页是一个特殊的、独特的页面,因此无需分成两步视图。因此,我没有理由需要视图脚本。但是,我确实创建了一个“views\scripts\index\index.phtml”来防止 ZF 抱怨。然而,我没有在我的布局中渲染它 - 因为不需要它。
任何回显的输出都会被捕获到
layout()->content
中(由布局从“默认”响应段自动分配)。因为我没有回显该片段,所以它的表现就好像回显的文本被抑制了。为了解决这个问题,我只需确保我正在回显内容片段。
即
,我的调试文本也被回显...将呈现为:
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:
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.
which, with my debug text being echoed too... would render as: