Zend 视图变量在视图助手中可用吗?

发布于 2024-11-08 23:59:17 字数 73 浏览 0 评论 0原文

我想知道 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

安静被遗忘 2024-11-15 23:59:17

由于所有视图助手都在其 $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.

驱逐舰岛风号 2024-11-15 23:59:17

那么你可以在视图助手中访问 $view 表单,我将举一个例子:
在下面的示例中,您可以设置和获取视图变量

<?php

class App_View_Helper_Job extends Zend_View_Helper_Abstract {

    public function setView(Zend_View_Interface $view) {
        $this->view = $view;
    }

    public function job() {
           $this->view->var1 = "testing var1 ";
           $this->view->var2 = $this->view->var1;
    }
}

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

<?php

class App_View_Helper_Job extends Zend_View_Helper_Abstract {

    public function setView(Zend_View_Interface $view) {
        $this->view = $view;
    }

    public function job() {
           $this->view->var1 = "testing var1 ";
           $this->view->var2 = $this->view->var1;
    }
}
浅浅淡淡 2024-11-15 23:59:17

你应该知道一件事:
视图助手的视图实例是在助手实例化时设置的,它不会在视图克隆时更新。因此,例如,如果从部分调用,您无法确定您正在使用哪一个。

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.

木森分化 2024-11-15 23:59:17

我发现当我在注册表中设置视图实例并从帮助程序获取它时,视图变量仍然存在。这是我在社交引擎项目中使用的代码片段

$view = Zend_Registry::get('Zend_View');
/*
 * Check data available and set it to local variable
 */
if(isset($view->localeTranslations[$key]))
{
   $translate = $view->localeTranslations[$key];
}

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

$view = Zend_Registry::get('Zend_View');
/*
 * Check data available and set it to local variable
 */
if(isset($view->localeTranslations[$key]))
{
   $translate = $view->localeTranslations[$key];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文