开发者

Zend Framework: How to unset the one stylesheet from the HeadLink helper

I have in Controller init() a list of common styles:

$this->view->headLink()->setStylesheet('/style/style.css');
$this->view->headLink()->appendStylesheet('/style/style2.css');
$this->view->headLink()->appendStylesheet('/style/style3.css');
$this->view->headLink()->appendStylesheet('/style/forms.css');
$this->view->headLink()->appendStylesheet('/sty开发者_运维问答le/ie_patches.css','all','lte IE 7');

what I need is the way to remove one of the stylesheets from the stack later in one of the action of this controller.

Appreciate your help, excuse my English


OR you can use

$this->view->headLink()->offsetUnset($offsetToBeRemoved); // offsetToBeRemoved should be integer

To find out the offsetToBeRemoved you can either get the iterator ( $this->view->headLink()->getIterator() ) or the container $this->view->headLink()->getContainer() ), loop thru it and get the key you're intrested in .


For example, if you want to remove '/style/style2.css' you can do in an action as follows:

    $headLinkContainer = $this->view->headLink()->getContainer();
    unset($headLinkContainer[1]);

This works because the container (i.e. instance of Zend_View_Helper_Placeholder_Container) extends ArrayObject. This means that you can manipulate your headLink elements as if you were using an array.

Hope this helps.


You can also set empty container like this:

$this->view->headLink()->setContainer(
    new Zend_View_Helper_Placeholder_Container()
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜