Issues

ZF-5435: offsetSetStylesheet: not correct order in headLink view helper

Issue Type: Bug Created: 2009-01-09T02:14:17.000+0000 Last Updated: 2009-02-06T09:49:48.000+0000 Status: Resolved Fix version(s): - 1.7.5 (16/Feb/09)

Reporter: Guido Jansen (herrserker) Assignee: Jon Whitcraft (sidhighwind) Tags: - Zend_View

Related issues: Attachments: - ZF-5435.patch

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

<pre class="highlight">
$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

<pre class="highlight">
$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

public function toString($indent = null)
{
    $indent = (null !== $indent)
            ? $this->getWhitespace($indent)
            : $this->getIndent();

    $items = array();
    $this->getContainer()->ksort(); //added by AK to fix bug ZF-5435
    foreach ($this as $item) {
        $items[] = $this->itemToString($item);
    }

    return $indent . implode($this->_escape($this->getSeparator()) . $indent, $items);
}

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

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts