Zend Framework: how to undo a single stylesheet from the HeadLink Assistant

I have a list of common styles in 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 a way to remove one of the stylesheets from the stack later in one of the actions of this controller.

Appreciate your help, sorry my English

+6
source share
3 answers

OR you can use

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

To find out the value of offsetToBeRemoved, you can either get an iterator ( $this->view->headLink()->getIterator() ) or a container $this->view->headLink()->getContainer() ), loop into it and get the key you're interested in.

+7
source

For example, if you want to remove '/style/style2.css', you can do it like this:

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

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

Hope this helps.

+4
source

You can also set an empty container as follows:

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

Source: https://habr.com/ru/post/891000/


All Articles