代码之家  ›  专栏  ›  技术社区  ›  Aron Rotteveel

当手动调用$View->render()时,Zend_View helpers不可用:如何修复它?

  •  0
  • Aron Rotteveel  · 技术社区  · 14 年前

    我最近发现 view helpers 手动调用时似乎不可用 $view->render() .

    在这种情况下,我有一个配置视图助手,可以很容易地从视图脚本中调用它,例如:

    $this->config()->some->param
    

    /** 
     * Within these view scripts, $this->config() is called, 
     * which results in an empty object
     */
    $mail->setBodyText($this->view->render('partials/invite/email/text.phtml'));
    $mail->setBodyHtml($this->view->render('partials/invite/email/html.phtml'));
    

    我是不是忽略了什么?这是一个错误还是有意的行为?我是否应该采取另一种手动呈现视图脚本的方法?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Viper_Sb    14 年前

    我们能看到更多的代码吗?

    到目前为止,我已经有了这个手动渲染视图。

    $view->setHelperPath('/path/to/helper/class');
    print $view->render('view.phtml');
    

    这是/path/to/helper/class中名为FooBar.php的类

    <?php
    class Zend_View_Helper_FooBar extends Zend_View_Helper_Abstract {
        public function fooBar()
        {
            return 'random string this will be the output';
        }
    }
    

    在view.pthml中

    print $this->fooBar();
    

    输出