CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • AttributeResolver
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget

Class BreadcrumbsHelper

BreadcrumbsHelper to register and display a breadcrumb trail for your views

Namespace: Cake\View\Helper

Property Summary

  • $Url public @property
    Cake\View\Helper\UrlHelper
  • $config protected
    array<string, mixed>

    Runtime config

  • $configInitialized protected
    bool

    Whether the config property has already been configured with defaults

  • $crumbs protected
    list<array{content: string, url: (array|string|null, options: array<string, mixed>}>

    The crumb list.

  • $defaultConfig protected
    array<string, mixed>

    Default config for the helper.

  • $helperInstances protected
    array<string, \Cake\View\Helper<Cake\View\View>>

    Loaded helper instances.

  • $helpers protected
    array<int|string, string|array<string, mixed>>

    Other helpers used by BreadcrumbsHelper.

  • $templater protected
    Cake\View\StringTemplate|null

    StringTemplate instance.

Method Summary

  • __construct() public

    Default Constructor

  • __debugInfo() public

    Returns an array that can be used to describe the internal state of this object.

  • __get() public

    Lazy loads helpers.

  • add() public

    Add a crumb to the end of the trail.

  • addClass() public

    Adds the given class to the element options

  • addMany() public

    Add multiple crumbs to the end of the trail.

  • configDelete() protected

    Deletes a single config key.

  • configRead() protected

    Reads a config key.

  • configShallow() public

    Merge provided config with existing config. Unlike config() which does a recursive merge for nested keys, this method does a simple merge.

    Setting a specific value:

    $this->configShallow('key', $value);

    Setting a nested value:

    $this->configShallow('some.nested.key', $value);

    Updating multiple config settings at the same time:

    $this->configShallow(['one' => 'value', 'another' => 'value']);
  • configWrite() protected

    Writes a config key.

  • confirm() protected

    Returns a string to be used as onclick handler for confirm dialogs.

  • deleteConfig() public

    Deletes a config key.

  • findCrumb() protected

    Search a crumb in the current stack which content matches the one provided as argument. If found, the index of the matching crumb will be returned.

  • formatTemplate() public

    Formats a template string with $data

  • getConfig() public

    Returns the config.

    Usage

    Reading the whole config:

    $this->getConfig();

    Reading a specific value:

    $this->getConfig('key');

    Reading a nested value:

    $this->getConfig('some.nested.key');

    Reading with default value:

    $this->getConfig('some-key', 'default-value');
  • getConfigOrFail() public

    Returns the config for this specific key.

    The config value for this key must exist, it can never be null.

  • getCrumbs() public

    Returns the crumb list.

  • getTemplate() public

    Gets templates to use or a specific template.

  • getTemplates() public

    Gets templates to use.

  • getView() public

    Get the view instance this helper is bound to.

  • implementedEvents() public

    Get the View callbacks this helper is interested in.

    By defining one of the callback methods a helper is assumed to be interested in the related event.

    Override this method if you need to add non-conventional event listeners. Or if you want helpers to listen to non-standard events.

  • initialize() public

    Constructor hook method.

    Implement this method to avoid having to overwrite the constructor and call parent.

  • insertAfter() public

    Insert a crumb after the first matching crumb with the specified content.

    Finds the index of the first crumb that matches the provided class, and inserts the supplied callable before it.

  • insertAt() public

    Insert a crumb at a specific index.

    If the index already exists, the new crumb will be inserted, before the existing element, shifting the existing element one index greater than before.

    If the index is out of bounds, an exception will be thrown.

  • insertBefore() public

    Insert a crumb before the first matching crumb with the specified content.

    Finds the index of the first crumb that matches the provided class, and inserts the supplied callable before it.

  • prepend() public

    Prepend a crumb to the start of the queue.

  • prependMany() public

    Prepend multiple crumbs to the start of the queue.

  • render() public

    Renders the breadcrumbs trail.

  • reset() public

    Removes all existing crumbs.

  • setConfig() public

    Sets the config.

    Usage

    Setting a specific value:

    $this->setConfig('key', $value);

    Setting a nested value:

    $this->setConfig('some.nested.key', $value);

    Updating multiple config settings at the same time:

    $this->setConfig(['one' => 'value', 'another' => 'value']);
  • setTemplates() public

    Sets templates to use.

  • templater() public

    Returns the templater instance.

Method Detail

__construct() ¶ public

__construct(TView $View, array<string, mixed> $config = [])

Default Constructor

Parameters
TView $View

The View this helper is being attached to.

array<string, mixed> $config optional

Configuration settings for the helper.

__debugInfo() ¶ public

__debugInfo(): array<string, mixed>

Returns an array that can be used to describe the internal state of this object.

Returns
array<string, mixed>

__get() ¶ public

__get(string $name): Cake\View\Helper<Cake\View\View>|null

Lazy loads helpers.

Parameters
string $name

Name of the property being accessed.

Returns
Cake\View\Helper<Cake\View\View>|null

Helper instance if helper with provided name exists

add() ¶ public

add(string $content, array|string|null $url = null, array<string, mixed> $options = []): $this

Add a crumb to the end of the trail.

Parameters
string $content

Represents the content of the crumb.

array|string|null $url optional

URL of the crumb. Either a string, an array of route params to pass to Url::build() or null / empty if the crumb does not have a link.

array<string, mixed> $options optional

Array of options. These options will be used as HTML attributes the crumb will be rendered in (a

  • tag by default). It accepts two special keys:

    • innerAttrs: An array that allows you to define attributes for the inner element of the crumb (by default, to the link)
    • templateVars: Specific template vars in case you override the templates provided.
  • Returns
    $this

    addClass() ¶ public

    addClass(array<string, mixed> $options, string $class, string $key = 'class'): array<string, mixed>

    Adds the given class to the element options

    Parameters
    array<string, mixed> $options

    Array options/attributes to add a class to

    string $class

    The class name being added.

    string $key optional

    the key to use for class. Defaults to 'class'.

    Returns
    array<string, mixed>

    Array of options with $key set.

    addMany() ¶ public

    addMany(array<array{content?: string, url?: (array|string|null, options?: array<string, mixed>}> $crumbs, array<string, mixed> $options = []): $this

    Add multiple crumbs to the end of the trail.

    Parameters
    array<array{content?: string, url?: (array|string|null, options?: array<string, mixed>}> $crumbs

    Array of crumbs to add. Arrays are expected to be of this form:

    • content The content of the crumb
    • link The link of the crumb. If not provided, no link will be made
    • options Options of the crumb. See description of params option of this method.
    array<string, mixed> $options optional

    Shared options for all crumbs. These options will be used as defaults for each crumb, with individual crumb options taking precedence. These options will be used as attributes HTML attribute the crumb will be rendered in (a

  • tag by default). It accepts two special keys:

    • innerAttrs: An array that allows you to define attributes for the inner element of the crumb (by default, to the link)
    • templateVars: Specific template vars in case you override the templates provided.
  • Returns
    $this

    configDelete() ¶ protected

    configDelete(string $key): void

    Deletes a single config key.

    Parameters
    string $key

    Key to delete.

    Returns
    void
    Throws
    Cake\Core\Exception\CakeException
    if attempting to clobber existing config

    configRead() ¶ protected

    configRead(string|null $key): $key is null ? array : mixed

    Reads a config key.

    Parameters
    string|null $key

    Key to read.

    Returns
    $key is null ? array : mixed

    configShallow() ¶ public

    configShallow(array<string, mixed>|string $key, mixed|null $value = null): $this

    Merge provided config with existing config. Unlike config() which does a recursive merge for nested keys, this method does a simple merge.

    Setting a specific value:

    $this->configShallow('key', $value);

    Setting a nested value:

    $this->configShallow('some.nested.key', $value);

    Updating multiple config settings at the same time:

    $this->configShallow(['one' => 'value', 'another' => 'value']);
    Parameters
    array<string, mixed>|string $key

    The key to set, or a complete array of configs.

    mixed|null $value optional

    The value to set.

    Returns
    $this

    configWrite() ¶ protected

    configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void

    Writes a config key.

    Parameters
    array<string, mixed>|string $key

    Key to write to.

    mixed $value

    Value to write.

    string|bool $merge optional

    True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.

    Returns
    void
    Throws
    Cake\Core\Exception\CakeException
    if attempting to clobber existing config

    confirm() ¶ protected

    confirm(string $okCode, string $cancelCode): string

    Returns a string to be used as onclick handler for confirm dialogs.

    Parameters
    string $okCode

    Code to be executed after user chose 'OK'

    string $cancelCode

    Code to be executed after user chose 'Cancel'

    Returns
    string

    "onclick" JS code

    deleteConfig() ¶ public

    deleteConfig(string $key): $this

    Deletes a config key.

    Parameters
    string $key

    Key to delete. It can be a dot separated string to delete nested keys.

    Returns
    $this

    findCrumb() ¶ protected

    findCrumb(string $content): int|null

    Search a crumb in the current stack which content matches the one provided as argument. If found, the index of the matching crumb will be returned.

    Parameters
    string $content

    Content to find.

    Returns
    int|null

    Index of the crumb found, or null if it can not be found.

    formatTemplate() ¶ public

    formatTemplate(string $name, array<string, mixed> $data): string

    Formats a template string with $data

    Parameters
    string $name

    The template name.

    array<string, mixed> $data

    The data to insert.

    Returns
    string

    getConfig() ¶ public

    getConfig(string|null $key = null, mixed $default = null): $key is null ? array : mixed

    Returns the config.

    Usage

    Reading the whole config:

    $this->getConfig();

    Reading a specific value:

    $this->getConfig('key');

    Reading a nested value:

    $this->getConfig('some.nested.key');

    Reading with default value:

    $this->getConfig('some-key', 'default-value');
    Parameters
    string|null $key optional

    The key to get or null for the whole config.

    mixed $default optional

    The return value when the key does not exist.

    Returns
    $key is null ? array : mixed

    Configuration data at the named key or null if the key does not exist.

    getConfigOrFail() ¶ public

    getConfigOrFail(string $key): mixed

    Returns the config for this specific key.

    The config value for this key must exist, it can never be null.

    Parameters
    string $key

    The key to get.

    Returns
    mixed

    Configuration data at the named key

    Throws
    InvalidArgumentException

    getCrumbs() ¶ public

    getCrumbs(): array

    Returns the crumb list.

    Returns
    array

    getTemplate() ¶ public

    getTemplate(string $template): string

    Gets templates to use or a specific template.

    Parameters
    string $template

    String for reading a specific template.

    Returns
    string

    getTemplates() ¶ public

    getTemplates(): array

    Gets templates to use.

    Returns
    array

    getView() ¶ public

    getView(): TView

    Get the view instance this helper is bound to.

    Returns
    TView

    The bound view instance.

    implementedEvents() ¶ public

    implementedEvents(): array<string, mixed>

    Get the View callbacks this helper is interested in.

    By defining one of the callback methods a helper is assumed to be interested in the related event.

    Override this method if you need to add non-conventional event listeners. Or if you want helpers to listen to non-standard events.

    Returns
    array<string, mixed>

    initialize() ¶ public

    initialize(array<string, mixed> $config): void

    Constructor hook method.

    Implement this method to avoid having to overwrite the constructor and call parent.

    Parameters
    array<string, mixed> $config

    The configuration settings provided to this helper.

    Returns
    void

    insertAfter() ¶ public

    insertAfter(string $matchingContent, string $content, array|string|null $url = null, array<string, mixed> $options = []): $this

    Insert a crumb after the first matching crumb with the specified content.

    Finds the index of the first crumb that matches the provided class, and inserts the supplied callable before it.

    Parameters
    string $matchingContent

    The content of the crumb you want to insert this one after.

    string $content

    Content of the crumb.

    array|string|null $url optional

    URL of the crumb. Either a string, an array of route params to pass to Url::build() or null / empty if the crumb does not have a link.

    array<string, mixed> $options optional

    Array of options. These options will be used as HTML attributes the crumb will be rendered in (a

  • tag by default). It accepts two special keys:

    • innerAttrs: An array that allows you to define attributes for the inner element of the crumb (by default, to the link)
    • templateVars: Specific template vars in case you override the templates provided.
  • Returns
    $this
    Throws
    LogicException
    In case the matching crumb can not be found.

    insertAt() ¶ public

    insertAt(int $index, string $content, array|string|null $url = null, array<string, mixed> $options = []): $this

    Insert a crumb at a specific index.

    If the index already exists, the new crumb will be inserted, before the existing element, shifting the existing element one index greater than before.

    If the index is out of bounds, an exception will be thrown.

    Parameters
    int $index

    The index to insert at.

    string $content

    Content of the crumb.

    array|string|null $url optional

    URL of the crumb. Either a string, an array of route params to pass to Url::build() or null / empty if the crumb does not have a link.

    array<string, mixed> $options optional

    Array of options. These options will be used as HTML attributes the crumb will be rendered in (a

  • tag by default). It accepts two special keys:

    • innerAttrs: An array that allows you to define attributes for the inner element of the crumb (by default, to the link)
    • templateVars: Specific template vars in case you override the templates provided.
  • Returns
    $this
    Throws
    LogicException
    In case the index is out of bound

    insertBefore() ¶ public

    insertBefore(string $matchingContent, string $content, array|string|null $url = null, array<string, mixed> $options = []): $this

    Insert a crumb before the first matching crumb with the specified content.

    Finds the index of the first crumb that matches the provided class, and inserts the supplied callable before it.

    Parameters
    string $matchingContent

    The content of the crumb you want to insert this one before.

    string $content

    Content of the crumb.

    array|string|null $url optional

    URL of the crumb. Either a string, an array of route params to pass to Url::build() or null / empty if the crumb does not have a link.

    array<string, mixed> $options optional

    Array of options. These options will be used as HTML attributes the crumb will be rendered in (a

  • tag by default). It accepts two special keys:

    • innerAttrs: An array that allows you to define attributes for the inner element of the crumb (by default, to the link)
    • templateVars: Specific template vars in case you override the templates provided.
  • Returns
    $this
    Throws
    LogicException
    In case the matching crumb can not be found

    prepend() ¶ public

    prepend(string $content, array|string|null $url = null, array<string, mixed> $options = []): $this

    Prepend a crumb to the start of the queue.

    Parameters
    string $content

    Represents the content of the crumb.

    array|string|null $url optional

    URL of the crumb. Either a string, an array of route params to pass to Url::build() or null / empty if the crumb does not have a link.

    array<string, mixed> $options optional

    Array of options. These options will be used as HTML attributes the crumb will be rendered in (a

  • tag by default). It accepts two special keys:

    • innerAttrs: An array that allows you to define attributes for the inner element of the crumb (by default, to the link)
    • templateVars: Specific template vars in case you override the templates provided.
  • Returns
    $this

    prependMany() ¶ public

    prependMany(array<array{content?: string, url?: (array|string|null, options?: array<string, mixed>}> $crumbs, array<string, mixed> $options = []): $this

    Prepend multiple crumbs to the start of the queue.

    Parameters
    array<array{content?: string, url?: (array|string|null, options?: array<string, mixed>}> $crumbs

    Array of crumbs to prepend. Arrays are expected to be of this form:

    • content The content of the crumb
    • link The link of the crumb. If not provided, no link will be made
    • options Options of the crumb. See description of params option of this method.
    array<string, mixed> $options optional

    Shared options for all crumbs. These options will be used as defaults for each crumb, with individual crumb options taking precedence. These options will be used as attributes HTML attribute the crumb will be rendered in (a

  • tag by default). It accepts two special keys:

    • innerAttrs: An array that allows you to define attributes for the inner element of the crumb (by default, to the link)
    • templateVars: Specific template vars in case you override the templates provided.
  • Returns
    $this

    render() ¶ public

    render(array<string, mixed> $attributes = [], array<string, mixed> $separator = []): string

    Renders the breadcrumbs trail.

    Parameters
    array<string, mixed> $attributes optional

    Array of attributes applied to the wrapper template. Accepts the templateVars key to allow the insertion of custom template variable in the template.

    array<string, mixed> $separator optional

    Array of attributes for the separator template. Possible properties are :

    • separator The string to be displayed as a separator
    • templateVars Allows the insertion of custom template variable in the template
    • innerAttrs To provide attributes in case your separator is divided in two elements.

    All other properties will be converted as HTML attributes and will replace the attrs key in the template. If you use the default for this option (empty), it will not render a separator.

    Returns
    string

    The breadcrumbs trail

    reset() ¶ public

    reset(): $this

    Removes all existing crumbs.

    Returns
    $this

    setConfig() ¶ public

    setConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this

    Sets the config.

    Usage

    Setting a specific value:

    $this->setConfig('key', $value);

    Setting a nested value:

    $this->setConfig('some.nested.key', $value);

    Updating multiple config settings at the same time:

    $this->setConfig(['one' => 'value', 'another' => 'value']);
    Parameters
    array<string, mixed>|string $key

    The key to set, or a complete array of configs.

    mixed|null $value optional

    The value to set.

    bool $merge optional

    Whether to recursively merge or overwrite existing config, defaults to true.

    Returns
    $this
    Throws
    Cake\Core\Exception\CakeException
    When trying to set a key that is invalid.

    setTemplates() ¶ public

    setTemplates(array<string, string> $templates): $this

    Sets templates to use.

    Parameters
    array<string, string> $templates

    Templates to be added.

    Returns
    $this

    templater() ¶ public

    templater(): Cake\View\StringTemplate

    Returns the templater instance.

    Returns
    Cake\View\StringTemplate

    Property Detail

    $Url ¶ public @property

    Type
    Cake\View\Helper\UrlHelper

    $config ¶ protected

    Runtime config

    Type
    array<string, mixed>

    $configInitialized ¶ protected

    Whether the config property has already been configured with defaults

    Type
    bool

    $crumbs ¶ protected

    The crumb list.

    Type
    list<array{content: string, url: (array|string|null, options: array<string, mixed>}>

    $defaultConfig ¶ protected

    Default config for the helper.

    Type
    array<string, mixed>

    $helperInstances ¶ protected

    Loaded helper instances.

    Type
    array<string, \Cake\View\Helper<Cake\View\View>>

    $helpers ¶ protected

    Other helpers used by BreadcrumbsHelper.

    Type
    array<int|string, string|array<string, mixed>>

    $templater ¶ protected

    StringTemplate instance.

    Type
    Cake\View\StringTemplate|null
    OpenHub
    Pingping
    Linode
    • Business Solutions
    • Showcase
    • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support

    Generated using CakePHP API Docs