Zend_View_Helper与Zend View部分脚本 [英] Zend_View_Helper vs Zend View Partial Script

查看:78
本文介绍了Zend_View_Helper与Zend View部分脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在路上的叉子.

This is my fork in the road.

我想在我的网页上显示某种按钮,并且我想在很多地方这样做.这个按钮"实际上就像是链接到其他页面的链接一样,所有按钮实例都将进入一个页面.

I want to display some sort of button on my webpage and I want to do it in many places. This 'button' is really just gonna act like a link to some other page and all the button instances are gonna go to one page.

我希望所有按钮都一样,除了它们的大小.

I want all the buttons to be the same except for maybe the size that they are.

现在,我应该使用带有html的部分脚本作为按钮并调用部分视图帮助器进行渲染,还是应该创建一个Zend_View_Helper来在调用按钮时返回html的HTML?

Now, should I use a partial script with the html for the button and call the partial view helper to render or should I create a Zend_View_Helper that will return the html for the button when I call it?

我知道我可以任一种摇摆,但您认为哪个更好?

I know that I could swing either way but which do you think is better?

我看到了一些东西:

  1. 该帮助程序可能会更好,因为它无需创建Zend_View的克隆之类的BIG对象即可完成部分任务.

  1. The helper might be better because it wouldn't have to create a BIG object like a clone of a Zend_View to do the partial.

HTML脚本人员更容易使用部分脚本.

The partial script would be easier for an html person to work with.

推荐答案

使用 $ this-> render()代替$ this-> partial().

Use $this->render() instead of $this->partial().

仅在需要对范围进行更多控制时才使用局部函数.就像您说的那样,它有很多开销,因为它必须创建一个新的Zend_View实例.不使用渲染.

Only use partials when you need more control over the scope. Like you said, it has a lot of overhead since it has to create a new Zend_View instance. Using render doesn't.

要解决您的实际问题,我建议在视图助手上使用渲染(或局部渲染),因为这样可以简化设计工作,并减少开销.查看助手用于自定义功能.

To touch upon your actual question, I recommend using render (or partial) over a view helper because it's much simpler for designs to work with, and there is less overhead. View helpers are for custom functionality.

一个好的经验法则是:您要包含content/html,还是要生成内容/应用转换.后者是助手.

A good rule of thumb is: do you want to include content/html, or do you want to generate content / apply transformations. Helpers are for the latter.

这篇关于Zend_View_Helper与Zend View部分脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆