代码之家  ›  专栏  ›  技术社区  ›  Yehia A.Salam

Zend框架中的自定义视图助手与动作视图助手

  •  0
  • Yehia A.Salam  · 技术社区  · 15 年前

    我想知道什么时候从视图中调用像这样的自定义视图助手

    <?php
    class Zend_View_Helper_MyHelper
    {
        public $view;
    
        public function setView(Zend_View_Interface $view)
        {
            $this->view = $view;
        }
    
        public function myHelper()
        {
            return $this->view->escape(
                ’This is being output from the custom helper <br />’
            );
        }
    }
    ?>
    

    谢谢。 耶希亚·A·萨拉姆

    2 回复  |  直到 13 年前
        1
  •  1
  •   Yes Barry    13 年前

    你为什么要这么做?

    class Zend_View_Helper_MyHelper extends Zend_View_Helper_Abstract
    {
        public function myHelper()
        {
            return "This is output from the custom helper<br/>";
        }
    }
    

    然后做一个:

    <?php echo $this->myHelper(); ?>

    在视图脚本上

        2
  •  1
  •   WayneZ    14 年前

    在ZF中,有View Helper和Action Helper,这里已经讨论了很多次了,所以我不重复了。但本问“什么是动作视图助手?”

        <div id="sidebar right">
        <div class="item">
           <?php echo $this->action('list',
                                    'comment',
                                    null,
                                    array('count' => 10)); ?>
        </div>
        </div>