在Zend_View_Helper_HeadScript
的toString()
方法,我注意到一個foreach()
環路上$this
,所以我想這和它的工作。這裏有一個用HeadScript擴展我寫的,說明了解決方案:
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(); ?>
如果我的解決辦法是在任何方面不清楚,讓我知道,我會更新,以澄清。
你如何使用它?我試圖讓這個工作http://blog.hines57.com/2011/03/13/zendframework-minify/只需要改變一個像在佈局echo $ this-> miniHeadScript() – max4ever 2011-05-03 14:29:25
@ max4ever - 我在解決方案中添加了更多細節。它重載了現有的'$ this-> headScript()'調用。更改爲'miniHeadScript()'是另一步。 – Sonny 2011-05-03 15:03:14
我不知道爲什麼,但foreach($ this ...)總是跳過我的配置,我發現解決方案是,遍歷$ this-> view-> headLink();我在博客上發佈了一些評論http://blog.hines57.com/2011/03/13/zendframework-minify/comment-page-1/#comment-353 – max4ever 2011-05-03 15:59:43