在我注意到一个循环的toString()
方法中,所以我尝试了它并且它有效。这是我编写的一个 HeadScript 扩展,它说明了解决方案:Zend_View_Helper_HeadScript
foreach()
$this
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
以下几行中指向我的助手:
$this->bootstrap('view');
$view = $this->getResource('view');
$view->addHelperPath('My/View/Helper', 'My_View_Helper');
在我的布局中,我有这一行:
<?php echo $this->headScript(); ?>
如果我的解决方案在任何方面都不清楚,请告诉我,我会更新它以澄清。