Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Method "headLink" does not exist #4105

Merged
merged 1 commit into from

5 participants

@Xunnamius

The following does not work:

echo $this->headLink()
    ->prependStylesheet($this->basePath($cacheBuster->bustPath('assets/css/local/forie.css')), 'screen', 'IE9')
    ->prependStylesheet($this->basePath($cacheBuster->bustPath('assets/css/application.css')))
    ->prependStylesheet($this->basePath($cacheBuster->bustPath('assets/css/vendor/responsive.css')))
    ->prependStylesheet($this->basePath($cacheBuster->bustPath('assets/css/vendor/bootstrap.css')))
    ->headLink(array(
        'rel' => 'shortcut icon', 
        'type' => 'image/vnd.microsoft.icon',
        'href' => $this->basePath('assets/img/favicon.ico')))
    ->headLink(array(
        'rel' => 'author',
        'href' => $this->basePath('humans.txt')))

The following works:

echo $this->headLink()
    ->prependStylesheet($this->basePath($cacheBuster->bustPath('assets/css/local/forie.css')), 'screen', 'IE9')
    ->prependStylesheet($this->basePath($cacheBuster->bustPath('assets/css/application.css')))
    ->prependStylesheet($this->basePath($cacheBuster->bustPath('assets/css/vendor/responsive.css')))
    ->prependStylesheet($this->basePath($cacheBuster->bustPath('assets/css/vendor/bootstrap.css')))
    ->__invoke(array(
        'rel' => 'shortcut icon', 
        'type' => 'image/vnd.microsoft.icon',
        'href' => $this-basePath('assets/img/favicon.ico')))
    ->__invoke(array(
        'rel' => 'author',
        'href' => $this->basePath('humans.txt')))

The documentation–which is, unfortunately, the only documentation available as I don't see any 2.0 version–states:

Example #19 HeadLink Helper Basic Usage
You may specify a headLink at any time. Typically, you will specify global links in your layout script, and application specific links in your application view scripts. In your layout script, in the <head> section, you will then echo the helper to output it.

And then gives the following example:

$this->headLink()->appendStylesheet('/styles/basic.css')
    ->headLink(array('rel' => 'icon',
        'href' => '/img/favicon.ico'),
        'PREPEND')
    ->prependStylesheet('/styles/moz.css',
        'screen',
        true,
        array('id' => 'my_stylesheet'));

It would seem that, contrary to the documentation and the intent of the accompanying test case (whose method name might contain the typo headScript instead of headLink), headLink cannot appear at any time when chaining methods.

@macnibblet

A simple fix would be to add a proxy method headLink on the helper to call __invoke but imho it would be better to change the documentation. Since that would create less confussion.

@Maks3w
Collaborator

I agree with to add a proxy method called headLink. Do you want to send a pull request?

@weierophinney weierophinney [#4105] Create proxy method `headLink()`
- Creates a proxy "headLink" method which allows us usage as described
  in the manual. Proxies to `__invoke`.
28a4760
@ezimuel ezimuel merged commit 28a4760 into zendframework:master
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-view
@weierophinney weierophinney [zendframework/zf2#4105] Create proxy method `headLink()`
- Creates a proxy "headLink" method which allows us usage as described
  in the manual. Proxies to `__invoke`.
9b635f6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 22, 2013
  1. @weierophinney

    [#4105] Create proxy method `headLink()`

    weierophinney authored
    - Creates a proxy "headLink" method which allows us usage as described
      in the manual. Proxies to `__invoke`.
This page is out of date. Refresh to see the latest.
View
15 library/Zend/View/Helper/HeadLink.php
@@ -57,6 +57,21 @@ public function __construct()
}
/**
+ * Proxy to __invoke()
+ *
+ * Allows calling $helper->headLink(), but, more importantly, chaining calls
+ * like ->appendStylesheet()->headLink().
+ *
+ * @param array $attributes
+ * @param string $placement
+ * @return HeadLink
+ */
+ public function headLink(array $attributes = null, $placement = Placeholder\Container\AbstractContainer::APPEND)
+ {
+ return call_user_func_array(array($this, '__invoke'), func_get_args());
+ }
+
+ /**
* headLink() - View Helper Method
*
* Returns current object instance. Optionally, allows passing array of
View
8 tests/ZendTest/View/Helper/HeadLinkTest.php
@@ -92,16 +92,16 @@ public function testOffsetSetThrowsExceptionWithoutArrayArgument()
$this->helper->offsetSet(1, 'foo');
}
- public function testCreatingLinkStackViaHeadScriptCreatesAppropriateOutput()
+ public function testCreatingLinkStackViaHeadLinkCreatesAppropriateOutput()
{
$links = array(
'link1' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'foo'),
'link2' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'bar'),
'link3' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'baz'),
);
- $this->helper->__invoke($links['link1'])
- ->__invoke($links['link2'], 'PREPEND')
- ->__invoke($links['link3']);
+ $this->helper->headLink($links['link1'])
+ ->headLink($links['link2'], 'PREPEND')
+ ->headLink($links['link3']);
$string = $this->helper->toString();
$lines = substr_count($string, PHP_EOL);
Something went wrong with that request. Please try again.