\Menu\Controller\ComponentBreadcrumbComponent

Breadcrumb component.

This component automatically attaches BreadcrumbHelper helper.

Summary

Methods
Properties
Constants
beforeFilter()
push()
__call()
cache()
dropCache()
No public properties found
No constants found
_urlChunk()
$_controller
$_cache
N/A
No private methods found
No private properties found
N/A

Properties

$_controller

$_controller : \Cake\Controller\Controller

The controller this component is attached to.

Type

\Cake\Controller\Controller

$_cache

$_cache : array

Used internally.

Type

array

Methods

beforeFilter()

beforeFilter(\Cake\Event\Event $event) : void

Initializes BreadcrumbComponent for use in the controller.

Parameters

\Cake\Event\Event $event

The event that was triggered

push()

push(array|string|null $crumbs, mixed $url) : $this

Adds a new crumb to the stack.

You can use this method without any argument, if you do, it will automatically try to guess the full breadcrumb path based on current URL (if current URL matches any URL in any of your menu links).

$this->Breadcrumb->push();

Also, you can can pass a string as first argument representing an URL, if you do, it will try to find that URL in in any of your menus, and then generate its corresponding breadcrumb.

$this->Breadcrumb->push('/admin/some/url');

Parameters

array|string|null $crumbs

Single crumb or an array of multiple crumbs to push at once. Or null for guess from current URL

mixed $url

If both $crumbs and $url are string values they will be used as title and URL respectively

Returns

$this —

For method chaining

__call()

__call(string $method, array $args) : mixed

Method delegation.

We try to dispatch unexisting method to \Menu\View\BreadcrumbRegistry class.

Parameters

string $method

Name of the method to be invoked

array $args

List of arguments passed to the function

Throws

\Cake\Core\Exception\Exception

When the method is unknown

Returns

mixed

cache()

cache(null|string $key, mixed $value) : mixed

Reads, writes or search internal class's cache.

Usages:

  • When reading if no cache key is found NULL will be returned. e.g. $null = static::cache('invalid-key');
  • When writing, this method return the value that was written. e.g. $value = static::cache('key', 'value');
  • Set both arguments to NULL to read the whole cache content at the moment. e.g. $allCache = static::cache()
  • Set key to null and value to anything to find the first key holding the given value. e.g. $key = static::cache(null, 'search key for this value'), if no key for the given value is found NULL will be returned.

Examples:

Writing cache:

static::cache('user_name', 'John');
// returns 'John'

static::cache('user_last', 'Locke');
// returns 'Locke'

Reading cache:

static::cache('user_name');
// returns: John

static::cache('unexisting_key');
// returns: null

static::cache();
// Reads the entire cache
// returns: ['user_name' => 'John', 'user_last' => 'Locke']

Searching keys:

static::cache(null, 'Locke');
// returns: user_last

static::cache(null, 'Unexisting Value');
// returns: null

Parameters

null|string $key

Cache key to read or write, set both $key and $value to get the whole cache information

mixed $value

Values to write into the given $key, or null indicates reading from cache

Returns

mixed

dropCache()

dropCache(string|null $key) : void

Drops the entire cache or a specific key.

Usage:

static::dropCache('user_cache'); // removes "user_cache" only
static::dropCache(); // removes every key

Parameters

string|null $key

Cache key to clear, if NULL the entire cache will be erased.

_urlChunk()

_urlChunk(string|null $url) : array

Returns possible URL combinations for the given URL or current request's URL.

Example:

For the given URL, /admin/content/manage/index/arg1/arg2?get1=v1&get2=v2 where:

  • /admin: Prefix.
  • /content: Plugin name.
  • /manage: Controller name.
  • /index: Controller's action.
  • /arg1 and /arg2: Action's arguments.
  • get1 and get2: GET arguments.

The following array will be returned by this method:

[
    "/admin/content/content/index/arg1/arg2?get1=v1&get2=v2",
    "/admin/content/content/arg1/arg2",
    "/admin/content/arg1/arg2",
    "/admin/content/arg1",
    "/admin/content",
]

Parameters

string|null $url

The URL to chunk as string value, set to null will use current request URL.

Returns

array