PHP code example of phalcon / breadcrumbs

1. Go to this page and download the library: Download phalcon/breadcrumbs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phalcon / breadcrumbs example snippets




use Phalcon\Breadcrumbs;

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



$this->breadcrumbs->add('Home', '/');



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



$this->breadcrumbs->setSeparator(' &raquo; ');



$this->breadcrumbs->setLastNotLinked(true);



$this->breadcrumbs->remove('/admin/user/create');

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



$this->breadcrumbs->update('/admin/user/remove', ['label' => '<strong class="red">Remove</strong>']);



$this->breadcrumbs->count();



$this->breadcrumbs->setTemplate(
    '<li><a href="{{link}}">{{icon}}{{label}}</a></li>', // linked
    '<li class="active">{{icon}}{{label}}</li>',         // not linked
    '<i class="fa fa-dashboard"></i>'                    // first icon
);



use Phalcon\Translate\Adapter\NativeArray as Translator;
use Phalcon\Breadcrumbs;

$messages = [
    'crumb-home'     => '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;
});



use Phalcon\Logger\Formatter\Line as FormatterLine;
use Phalcon\Logger\Adapter\File as FileLogger;
use Phalcon\Breadcrumbs;

/**
 * Initialize the Logger.
 *
 * @var $config array
 * @var $di \Phalcon\Di
 */
$di->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;
});



use Phalcon\Breadcrumbs;
use Phalcon\Events\Manager as EventsManager;

// Initialize the Events Manager.
$di->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;
});
html
<ol class="breadcrumb">
     $this->breadcrumbs->output();