src/View/Helper/NavbarHelper.php
public function link($name, $url = '', array $options = [], array $linkOptions = []) {
        $url = $this->Url->build($url);
        $options += [
            'active' => [],
            'templateVars' => []
        ];
        $linkOptions += [
            'templateVars' => []
        ];
        if (is_string($options['active'])) {
            $options['active'] = [];
        }
        if ($this->getConfig('autoActiveLink') && is_array($options['active'])) {
            $options['active'] = $this->compareUrls($url, null, $options['active']);
        }
        $active = $options['active'] ? 'Active' : '';
        $level = $this->_level > 1 ? 'inner' : 'outer';
        $template = $level.'MenuItem'.$active;
        $linkTemplate = $level.'MenuItemLink'.$active;
        $link = $this->formatTemplate($linkTemplate, [
            'content' => $name,
            'url' => $url,
            'attrs' => $this->templater()->formatAttributes($linkOptions),
            'templateVars' => $linkOptions['templateVars']
        ]);
        return $this->formatTemplate($template, [
            'link' => $link,
            'attrs' => $this->templater()->formatAttributes($options, ['active']),
            'templateVars' => $options['templateVars']
        ]);
    }
public function link($name, $url = '', array $options = [], array $linkOptions = []) {
        $url = $this->Url->build($url);
        $options += [
            'active' => [],
            'templateVars' => []
        ];
        $linkOptions += [
            'templateVars' => []
        ];
        if (is_string($options['active'])) {
            $options['active'] = [];
        }
        if ($this->getConfig('autoActiveLink') && is_array($options['active'])) {
            $options['active'] = $this->compareUrls($url, null, $options['active']);
        }
        $active = $options['active'] ? 'Active' : '';
        $level = $this->_level > 1 ? 'inner' : 'outer';
        $template = $level.'MenuItem'.$active;
        $linkTemplate = $level.'MenuItemLink'.$active;
        $link = $this->formatTemplate($linkTemplate, [
            'content' => $name,
            'url' => $url,
            'attrs' => $this->templater()->formatAttributes($linkOptions),
            'templateVars' => $linkOptions['templateVars']
        ]);
        return $this->formatTemplate($template, [
            'link' => $link,
            'attrs' => $this->templater()->formatAttributes($options, ['active']),
            'templateVars' => $options['templateVars']
        ]);
    }
public function link ( $ name , $ url = '' , array $ options = [ ] , array $ linkOptions = [ ] ) { $ url = $ this -> Url -> build ( $ url ) ; $ options += [ 'active' => [ ] , 'templateVars' => [ ] ] ; $ linkOptions += [ 'templateVars' => [ ] ] ; if ( is_string ( $ options [ 'active' ] ) ) { $ options [ 'active' ] = [ ] ; } if ( $ this -> getConfig ( 'autoActiveLink' ) && is_array ( $ options [ 'active' ] ) ) { $ options [ 'active' ] = $ this -> compareUrls ( $ url , null , $ options [ 'active' ] ) ; } $ active = $ options [ 'active' ] ? 'Active' : '' ; $ level = $ this -> _level > 1 ? 'inner' : 'outer' ; $ template = $ level . 'MenuItem' . $ active ; $ linkTemplate = $ level . 'MenuItemLink' . $ active ; $ link = $ this -> formatTemplate ( $ linkTemplate , [ 'content' => $ name , 'url' => $ url , 'attrs' => $ this -> templater ( ) -> formatAttributes ( $ linkOptions ) , 'templateVars' => $ linkOptions [ 'templateVars' ] ] ) ; return $ this -> formatTemplate ( $ template , [ 'link' => $ link , 'attrs' => $ this -> templater ( ) -> formatAttributes ( $ options , [ 'active' ] ) , 'templateVars' => $ options [ 'templateVars' ] ] ) ; }
Add a link to the navbar or to a menu.

Encapsulate links with `beginMenu()`, `endMenu()` to create
a horizontal hover menu in the navbar or a dropdown menu.

### Options

- `active` Indicates if the link is the current one. Default is automatically
deduced if `autoActiveLink` is on, otherwize default is `false`.
- `templateVars` Provide template variables for the templates.
- Other attributes will be assigned to the navbar link element.

@param string $name The link text.
@param string|array $url The link URL (CakePHP way).
@param array $options Array of attributes for the wrapper tag.
@param array $linkOptions Array of attributes for the link.

@return string A HTML tag wrapping the link.
Add a link to the navbar or to a menu .