【问题标题】:cakephp helper call function of other helpercakephp helper 调用其他 helper 的函数
【发布时间】:2016-05-09 13:33:42
【问题描述】:

我想要实现的是自动加载脚本和 css 的助手。 所以基本上这个想法是在每个帮助器上都有一个功能,它正在加载专用于帮助器的脚本/样式。 我想这可以通过一个控制助手来实现,它查询所有活动助手,然后执行脚本/样式加载函数。

我在文档中找不到的是:

  • 助手如何查询活动助手对象的列表

【问题讨论】:

    标签: cakephp cakephp-3.0


    【解决方案1】:

    您可以使用(参见View::helpers)查询ViewHelperRegistry

    $this->_View->helpers();
    

    获得注册表后,您可以使用HelperRegistry::loaded() 获取已加载帮助程序的名称,并使用HelperRegistry::get() 检索它们:

    // Inside your helper:
    $registry = $this->_View->helpers();
    foreach ($registry->loaded() as $name) {
        $helper = $registry->get($name);
    }
    

    免责声明:以上代码未经测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-09
      • 2011-06-29
      相关资源
      最近更新 更多