本文介绍了在Zend HeadScript View Helper中修改堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决此问题从完全不同的角度来看,因为看起来我无法那样实现目标.

I am trying to attack this problem from a completely different angle, because it doesn't look like I can achieve my goal that way.

我想遍历 HeadScript View Helper ,然后对其进行修改. 文档为此,以及其他一些视图助手做出了这样的声明:

I want to loop over the item stack in the HeadScript View Helper, and make modifications to it. The documentation for this and some of the other view helpers makes this statement:

那么,这个对象返回"在哪里?我在这里错过了一个难题.

So, where is this "object returned"? I am missing a piece of the puzzle here.

感谢您的帮助!

推荐答案

Zend_View_Helper_HeadScripttoString()方法中,我注意到了$this上的foreach()循环,所以我尝试了一下,并且它起作用了.这是我编写的HeadScript扩展,用于说明解决方案:

In the toString() method of Zend_View_Helper_HeadScript I noticed a foreach() loop on $this, so I tried that and it worked. Here's a HeadScript extension I wrote that illustrates the solution:

class My_View_Helper_HeadScript extends Zend_View_Helper_HeadScript
{
    public function toString($indent = null)
    {
        $files = array();
        foreach ($this as $key => $item) {
            if (!empty($item->attributes)
                    && array_key_exists('src', $item->attributes)
                    && ('scripts' == substr($item->attributes['src'], 1, 7))) {
                $files[] = $item->attributes['src'];
                unset($this[$key]);
            }
        }
        if (0 < count($files)) {
            $this->prependFile('/combo.php?type=scripts&files=' . implode(',', $files));
        }
        return parent::toString($indent);
    }
}

Bootstrap.php中,以下几行指向我的助手:

In Bootstrap.php the following lines to point to my helpers:

$this->bootstrap('view');
$view = $this->getResource('view');
$view->addHelperPath('My/View/Helper', 'My_View_Helper');

在我的布局中,我有这行:

In my layout, I have this line:

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


如果我的解决方案仍然不清楚,请告诉我,我将对其进行更新以澄清问题.


If my solution is unclear in any way, let me know and I'll update it to clarify.

这篇关于在Zend HeadScript View Helper中修改堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 00:19