Zend HeadScript Görünüm Helper Stack değiştirin

1 Cevap php

Amacım bu şekilde elde edebilirsiniz gibi görünmüyor, çünkü tamamen farklı bir açıdan this problem saldırmak için çalışıyorum.

Ben HeadScript View Helper olarak madde yığının üzerinde döngü istiyorum, ve buna değişiklikler yapmak. The documentation Bu ve diğer görünümü yardımcıları bazıları için bu açıklamayı yapar:

HeadScript overrides each of append(), offsetSet(), prepend(), and set() to enforce usage of the special methods as listed above. Internally, it stores each item as a stdClass token, which it later serializes using the itemToString() method. This allows you to perform checks on the items in the stack, and optionally modify these items by simply modifying the object returned.

Peki, nerede bu "nesne döndü" dir? Ben burada bulmacanın bir parçası eksik.

Yardımlarınız için teşekkürler!

1 Cevap

Ve toString() yöntemde Zend_View_Helper_HeadScript I $this bir foreach() döngü fark ettim, yani ben bunu denedim ve işe yaradı. İşte çözüm göstermektedir yazdığım bir HeadScript uzantısıdır:

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 şu satırlar benim yardımcıları işaret etmek için:

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

Benim düzeni, ben bu satırı var:

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

Benim çözüm herhangi bir şekilde belirsiz ise, bana bildirin ve ben bunu açıklamak için güncelleme olacak.