Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sergeyklay/breadcrumbs

Powerful and flexible component for building site breadcrumbs.
https://github.com/sergeyklay/breadcrumbs

breadcrumbs crumbs phalcon php

Last synced: 3 months ago
JSON representation

Powerful and flexible component for building site breadcrumbs.

Awesome Lists containing this project

README

        

# Phalcon Breadcrumbs [![Build Status][:travis-badge:]][:travis-url:]

![Breadcrumbs Screenshot][:screenshot:]

Phalcon Breadcrumbs is a powerful and flexible component for building site breadcrumbs.
You can adapt it to your own needs or improve it if you want.

Please write us if you have any feedback.

Thanks!

## NOTE

The `master` branch will always contain the latest stable version. If you wish
to check older versions or newer ones currently under development, please
switch to the relevant branch/tag.

## Getting Started

### Requirements

To use this component, you need at least:

* [Composer][:composer:]
* PHP >= 5.5
* [Phalcon Framework release][:phalcon:] extension enabled >= 2.x < 4.x

**NOTE:** Support for legacy PHP versions (down to 7.0) is provided on a best-effort basis.

### Installing

```sh
$ composer require sergeyklay/breadcrumbs
```

### Define your breadcrumbs

We recommend registering it with your application's services for even easier use:

```php
setShared('breadcrumbs', function () {
return new Breadcrumbs;
});
```

**Adding a crumb with a link:**

```php
breadcrumbs->add('Home', '/');
```

**Adding a crumb without a link (normally the last one):**

```php
breadcrumbs->add('User', null, ['linked' => false]);
```

**Output crumbs:**

Php Engine
```html


```

Volt Engine
```volt


```

**Change crumb separator:**

```php
breadcrumbs->setSeparator(' » ');
```

**Make The last element is always not a link:**

```php
breadcrumbs->setLastNotLinked(true);
```

**Delete a crumb (by url):**

```php
breadcrumbs->remove('/admin/user/create');

// remove a crumb without an url
$this->breadcrumbs->remove(null);
```

**Update an existing crumb:**

```php
breadcrumbs->update('/admin/user/remove', ['label' => 'Remove']);
```

**Count crumbs:**
```php
breadcrumbs->count();
```

**Sets rendering template:**

```php
breadcrumbs->setTemplate(
'

  • {{icon}}{{label}}
  • ', // linked
    '
  • {{icon}}{{label}}
  • ', // not linked
    '' // first icon
    );
    ```

    **Multi-language support:**

    ```php
    'Home',
    'crumb-user' => 'User',
    'crumb-settings' => 'Settings',
    'crumb-profile' => 'Profile',
    ];

    // Initialize the Translate adapter.
    $di->setShared('translate', function () use ($messages) {
    return new Translator(['content' => $messages]);
    });

    // Initialize the Breadcrumbs component.
    $di->setShared('breadcrumbs', function () {
    return new Breadcrumbs;
    });
    ```

    **Errors logging:**

    ```php
    setShared('logger', function ($filename = null, $format = null) use ($config) {
    $formatter = new FormatterLine($config->get('logger')->format, $config->get('logger')->date);
    $logger = new FileLogger($config->get('logger')->path . $config->get('logger')->filename);

    $logger->setFormatter($formatter);
    $logger->setLogLevel($config->get('logger')->logLevel);

    return $logger;
    });

    // Initialize the Breadcrumbs component.
    $di->setShared('breadcrumbs', function () {
    return new Breadcrumbs;
    });
    ```

    ### Events

    ```php
    setShared('eventsManager', function () {
    return new EventsManager;
    });

    // Initialize the Breadcrumbs component.
    $di->setShared('breadcrumbs', function () use ($di) {
    $manager = $di->getShared('eventsManager');
    $manager->attach('breadcrumbs', function ($event, $connection) {
    // We stop the event if it is cancelable
    if ($event->isCancelable()) {
    // Stop the event, so other listeners will not be notified about this
    $event->stop();
    }

    // Receiving the data from the event context
    print_r($event->getData());
    });

    $breadcrumbs = new Breadcrumbs;
    $breadcrumbs->setEventsManager($manager);

    return $breadcrumbs;
    });
    ```

    Available events:

    ```
    breadcrumbs:beforeAdd
    breadcrumbs:afterAdd
    breadcrumbs:beforeOutput
    breadcrumbs:afterOutput
    breadcrumbs:beforeTranslate
    breadcrumbs:afterTranslate
    breadcrumbs:beforeLogging
    breadcrumbs:afterLogging
    breadcrumbs:beforeRemove
    breadcrumbs:afterRemove
    breadcrumbs:beforeUpdate
    breadcrumbs:afterUpdate
    breadcrumbs:beforeSetTemplate
    breadcrumbs:afterSetTemplate
    ```

    ## Copyright

    Phalcon Breadcrumbs is open-sourced software licensed under the [New BSD License][:license:].
    © Serghei Iakovlev

    [:composer:]: https://getcomposer.org/
    [:phalcon:]: https://github.com/sergeyklay/cphalcon/releases
    [:license:]: https://github.com/sergeyklay/breadcrumbs/blob/master/LICENSE.txt
    [:screenshot:]: https://github.com/sergeyklay/breadcrumbs/blob/master/docs/breadcrumbs.png
    [:travis-url:]: https://travis-ci.com/sergeyklay/breadcrumbs
    [:travis-badge:]: https://travis-ci.com/sergeyklay/breadcrumbs.svg?branch=master