Matt Lowden

Clear head scripts & links in ZEND

October 8th 2013

When using the ZEND Framework there's a chance that you will run into situations where you want to clear all of the head scripts and CSS that you've appended to the document via the headScript() & headLink() View Helpers.

In order to reset all of the scripts and CSS you've added to a document you can use the following. This example assumes the code is placed in a Controller.

$this->view->headScript()->exchangeArray( array() );
$this->view->headLink()->exchangeArray( array() );

To give a little context to this example take a look at the following.

$this->view->headScript()->appendFile('js/jquery.js');

$this->view->headScript()->exchangeArray( array() );

$this->view->headScript()->appendFile('js/main.js');

In this example the file js/jquery.js is appended to the document, the scripts are then cleared and js/main.js is appended to the document.

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

The above code within one of the layouts will output the following as js/jquery.js was cleared from the registry.

<script type="text/javascript" src="js/main.js"></script>
cialis online

Köpa Generisk viagra online i sverige