简体   繁体   English

Zend Framework:如何从HeadLink助手中取消设置一个样式表

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

I have in Controller init() a list of common styles: 我在Controller init()中有一个常见样式列表:

$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('/style/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 . 要查找offsetToBeRemoved,您可以获取迭代器( $this->view->headLink()->getIterator() )或容器$this->view->headLink()->getContainer() ),循环$this->view->headLink()->getContainer()它并获得你感兴趣的钥匙。

For example, if you want to remove '/style/style2.css' you can do in an action as follows: 例如,如果要删除“/style/style2.css”,可以按如下方式执行操作:

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

This works because the container (ie instance of Zend_View_Helper_Placeholder_Container ) extends ArrayObject . 这是有效的,因为容器(即Zend_View_Helper_Placeholder_Container实例)扩展了ArrayObject This means that you can manipulate your headLink elements as if you were using an array. 这意味着您可以像使用数组一样操纵headLink元素。

Hope this helps. 希望这可以帮助。

You can also set empty container like this: 你也可以像这样设置空容器:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM