In Zend Framework applications, what purpose does

2019-05-28 21:00发布

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

1条回答
贼婆χ
2楼-- · 2019-05-28 21:27

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.

查看更多
登录 后发表回答