ZF-5435: offsetSetStylesheet: not correct order in headLink view helper
Description
in the headlink view helper one can use the offsetSetStylesheet method to set certain indexes of the inside ArrayObject-type container,
but when you want to put out the stylesheets the order of output is not the one defined by index, but by insertion time order.
You can fix this by adding
$this->getContainer()->asort();
into the toString method of Zend/View/Helper/HeadLink but I don't know, if this is the best solution or if the issue lies a bit more under the surface (maybe the iterator of the ArrayObject doesn't work as expected.
One can help oneself by calling asort before calling the toString-method in the view script
$this->headStyle()->getContainer()->asort();
echo $this->headStyle();
The same should apply to headScript, headMeta and headStyle
Comments
Posted by Matthew Weier O'Phinney (matthew) on 2009-01-09T03:40:50.000+0000
Assigning to Ralph.
Posted by Ashley Kitson (akzincdig) on 2009-02-01T01:01:33.000+0000
I confirm that this is still an issue in 1.7.2.
$this->view->headLink()->offsetSetStylesheet(1,$someStylesheet,$media); $this->view->headLink()->offsetSetStylesheet(10,$anotherStylesheet,$media); $this->view->headLink()->offsetSetStylesheet(20,$yetAnotherStylesheet,$media); $this->view->headLink()->offsetSetStylesheet(5,$insertedStylesheet,$media);
will render the style sheets to the output in order of insertion, not the offset order
Posted by Ashley Kitson (akzincdig) on 2009-02-01T01:27:35.000+0000
Adding the line
$this->getContainer()->ksort();
(not asort() as previously stated)
prior to line 310 - foreach ($this as $item) {
fixes the problem
Posted by Ashley Kitson (akzincdig) on 2009-02-01T01:31:10.000+0000
Sorry - should have given full script ref.
Script to amend is Zend_View_Helper_HeadLink.php
Affected function is
Posted by Jon Whitcraft (sidhighwind) on 2009-02-06T09:14:50.000+0000
This bug also affected the other view headerView Helpers so i rolled them all into one patch.
Posted by Jon Whitcraft (sidhighwind) on 2009-02-06T09:27:35.000+0000
Fix with r13995 and move into 1.7 release branch with r13996