问题描述
我对视图助手做了什么(/ view / helpers)有了一个概念,但我不知道视图过滤器(/ view / filters)是什么,或者它的用途是什么,请问一下,这个问题?
Thank You =)
渲染视图,Zend_View通过调用过滤器对象上的 filter()
方法将输出传递给您已注册的任何过滤器。
过滤器的一个用途是缩小HTML输出,剥离注释和空白以减少通过网络发送的内容的大小。
理论上,你可以编写更复杂的过滤器,修改DOM,修改,隐藏或删除页面元素。我不会这样做,因为视图在第一遍渲染元素的效率更高,而不是在渲染之后用DOM操作调整它们。或者您可以修改内容,例如将英语翻译成法语(如果您有自动的方式,ZF不提供这种功能)。
Zend_View过滤器不幸的是没有记录,这让我觉得没有什么需求。我怀疑视图过滤器基本上是的受害者。他们没有一个好的使用案例。
I have an idea of what view helpers do (/view/helpers), but I have no idea what a view filter (/view/filters) is, or what its used for, can some one please shed some light on the matter?
Thank You =)
At the end of rendering a view, Zend_View passes the output to any filter(s) you have registered, by calling the filter()
method on the filter object.
One use of a filter could be to minify HTML output, stripping comments and whitespace to reduce the size of the content to send over the network.
In theory, you could write more sophisticated filters, that modify the DOM, altering, hiding or removing page elements. I wouldn't do that because it's more efficient for the view to render elements right on the first pass, than to tweak them with DOM operations after rendering. Or you could modify content, such as to translate English into French on the fly (if you had an automatic way of doing that, which ZF does not provide).
Zend_View filter is unfortunately undocumented, which makes me think there is little demand for it. I suspect that view filters are basically a victim of YAGNI. They were implemented without a good use case in mind.
这篇关于在Zend框架应用程序中,/ views /过滤器的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!