在Zend框架应用程序中,/ views /过滤器的用途是什么?

编程入门 行业动态 更新时间:2024-10-26 08:27:51
本文介绍了在Zend框架应用程序中,/ views /过滤器的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对视图助手做了什么(/ view / helpers)有了一个概念,但我不知道视图过滤器(/ view / filters)是什么,或者它的用途是什么,请问一下,这个问题?

Thank You =)

解决方案

渲染视图,Zend_View通过调用过滤器对象上的 filter()方法将输出传递给您已注册的任何过滤器。

过滤器的一个用途是缩小HTML输出,剥离注释和空白以减少通过网络发送的内容的大小。

理论上,你可以编写更复杂的过滤器,修改DOM,修改,隐藏或删除页面元素。我不会这样做,因为视图在第一遍渲染元素的效率更高,而不是在渲染之后用DOM操作调整它们。或者您可以修改内容,例如将英语翻译成法语(如果您有自动的方式,ZF不提供这种功能)。

Zend_View过滤器不幸的是没有记录,这让我觉得没有什么需求。我怀疑视图过滤器基本上是 YAGNI 的受害者。他们没有一个好的使用案例。

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 /过滤器的用途是什么?

本文发布于:2023-11-05 04:00:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559836.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   应用程序   框架   用途   Zend

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!