Zend 视图变量在视图助手中可用吗?
我想知道 Zend 视图变量在我的视图助手类中是否可用,而不直接将它们作为参数传递,
谢谢
Luca
I am wondering if Zend view variables are available in my view helper class without passing them in directly as parameters
thanks
Luca
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于所有视图助手都在其
$view
属性中引用视图,因此答案是肯定的。从助手方面您不会知道哪些属性可用。最好在呼叫或施工时将任何所需的属性传递给帮助者。
As all view helpers have reference to the view in their
$view
property, the answer is yes.What you won't know from the helper side is which properties are available. It would be better to pass any required properties to the helper at call or construction time.
那么你可以在视图助手中访问
$view
表单,我将举一个例子:在下面的示例中,您可以设置和获取视图变量
well you can access
$view
form inside the view helper , i will give an example :in the example below you can set and get view vars
你应该知道一件事:
视图助手的视图实例是在助手实例化时设置的,它不会在视图克隆时更新。因此,例如,如果从部分调用,您无法确定您正在使用哪一个。
You should know one thing:
view helper's view instance is the one set on helper instantiation It is not updated on view cloning. So you can't say for sure which one you're using if called from partial for example.
我发现当我在注册表中设置视图实例并从帮助程序获取它时,视图变量仍然存在。这是我在社交引擎项目中使用的代码片段
I found that when I set the view instance in registry and get it from helper the view variables stays. Here is a code snippet I used in my social engine project