public function render($items, $config = [])
    {
        if ($this->_rendering) {
            throw new FatalErrorException(__d('menu', 'Loop detected, MenuHelper already rendering.'));
        }

        $items = $this->_prepareItems($items);
        if (empty($items)) {
            return '';
        }

        list($config, $attrs) = $this->_prepareOptions($config);
        $this->_rendering = true;
        $this->countItems($items);
        $this->config($config);

        if ($this->config('breadcrumbGuessing')) {
            $this->Link->config(['breadcrumbGuessing' => $this->config('breadcrumbGuessing')]);
        }

        $out = '';
        if (intval($this->config('split')) > 1) {
            $out .= $this->_renderPart($items, $config, $attrs);
        } else {
            $out .= $this->formatTemplate('root', [
                'attrs' => $this->templater()->formatAttributes($attrs),
                'content' => $this->_render($items)
            ]);
        }

        if ($this->config('beautify')) {
            include_once Plugin::classPath('Menu') . 'Lib/htmLawed.php';
            $tidy = is_bool($this->config('beautify')) ? '1t0n' : $this->config('beautify');
            $out = htmLawed($out, compact('tidy'));
        }

        $this->_clear();

        return $out;
    }
public function render($items, $config = [])
    {
        if ($this->_rendering) {
            throw new FatalErrorException(__d('menu', 'Loop detected, MenuHelper already rendering.'));
        }

        $items = $this->_prepareItems($items);
        if (empty($items)) {
            return '';
        }

        list($config, $attrs) = $this->_prepareOptions($config);
        $this->_rendering = true;
        $this->countItems($items);
        $this->config($config);

        if ($this->config('breadcrumbGuessing')) {
            $this->Link->config(['breadcrumbGuessing' => $this->config('breadcrumbGuessing')]);
        }

        $out = '';
        if (intval($this->config('split')) > 1) {
            $out .= $this->_renderPart($items, $config, $attrs);
        } else {
            $out .= $this->formatTemplate('root', [
                'attrs' => $this->templater()->formatAttributes($attrs),
                'content' => $this->_render($items)
            ]);
        }

        if ($this->config('beautify')) {
            include_once Plugin::classPath('Menu') . 'Lib/htmLawed.php';
            $tidy = is_bool($this->config('beautify')) ? '1t0n' : $this->config('beautify');
            $out = htmLawed($out, compact('tidy'));
        }

        $this->_clear();

        return $out;
    }
public function render ( $ items , $ config = [ ] ) { if ( $ this -> _rendering ) { throw new FatalErrorException ( __d ( 'menu' , 'Loop detected, MenuHelper already rendering.' ) ) ; } $ items = $ this -> _prepareItems ( $ items ) ; if ( empty ( $ items ) ) { return '' ; } list ( $ config , $ attrs ) = $ this -> _prepareOptions ( $ config ) ; $ this -> _rendering = true ; $ this -> countItems ( $ items ) ; $ this -> config ( $ config ) ; if ( $ this -> config ( 'breadcrumbGuessing' ) ) { $ this -> Link -> config ( [ 'breadcrumbGuessing' => $ this -> config ( 'breadcrumbGuessing' ) ] ) ; } $ out = '' ; if ( intval ( $ this -> config ( 'split' ) ) > 1 ) { $ out .= $ this -> _renderPart ( $ items , $ config , $ attrs ) ; } else { $ out .= $ this -> formatTemplate ( 'root' , [ 'attrs' => $ this -> templater ( ) -> formatAttributes ( $ attrs ) , 'content' => $ this -> _render ( $ items ) ] ) ; } if ( $ this -> config ( 'beautify' ) ) { include_once Plugin :: classPath ( 'Menu' ) . 'Lib/htmLawed.php' ; $ tidy = is_bool ( $ this -> config ( 'beautify' ) ) ? '1t0n' : $ this -> config ( 'beautify' ) ; $ out = htmLawed ( $ out , compact ( 'tidy' ) ) ; } $ this -> _clear ( ) ; return $ out ; }
Renders a nested menu.

This methods renders a HTML menu using a `threaded` result set:

```php
// In controller:
$this->set('links', $this->Links->find('threaded'));

// In view:
echo $this->Menu->render('links');
```

### Options:

You can pass an associative array `key => value`. Any `key` not in
`$_defaultConfig` will be treated as an additional attribute for the top
level UL (root). If `key` is in `$_defaultConfig` it will temporally
overwrite default configuration parameters, it will be restored to its
default values after rendering completes:

- `formatter`: Callable method used when formating each item.
- `activeClass`: CSS class to use when an item is active (its URL matches current URL).
- `firstItemClass`: CSS class for the first item.
- `lastItemClass`: CSS class for the last item.
- `hasChildrenClass`: CSS class to use when an item has children.
- `split`: Split menu into multiple root menus (multiple UL's)
- `templates`: The templates you want to use for this menu. Any templates
will be merged on top of the already loaded templates. This option can
either be a filename in App/config that contains the templates you want
to load, or an array of templates to use.

You can also pass a callable function as second argument which will be
used as formatter:

```php
echo $this->Menu->render($links, function ($link, $info) {
// render $item here
});
```

Formatters receives two arguments, the item being rendered as first argument
and information abut the item (has children, depth, etc) as second.

You can pass the ID or slug of a menu as fist argument to render that menu's
links:

```php
echo $this->Menu->render('management');

// OR

echo $this->Menu->render(1);
```

@param int|string|array|\Cake\Collection\Collection $items Nested items
to render, given as a query result set or as an array list. Or an integer as
menu ID in DB to render, or a string as menu Slug in DB to render.
@param callable|array $config An array of HTML attributes and options as
described above or a callable function to use as `formatter`
@return string HTML
@throws \Cake\Error\FatalErrorException When loop invocation is detected,
that is, when "render()" method is invoked within a callable method when
rendering menus.
Renders a nested menu .