Download the PHP package naucon/breadcrumbs without Composer

On this page you can find all versions of the php package naucon/breadcrumbs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package breadcrumbs

naucon Breadcrumbs Package

About

The breadcrumb package helps to integrate a common breadcrumb navigation into a web application. The package includes two components: A breadcrumbs class to add breadcrumb elements and a breadcrumbs helper to render html markup in php or smarty templates.

Features

Compatibility

Dependencies

Installation

install the latest version via composer

composer require naucon/breadcrumbs

Usage

initialize

To build a breadcrumb menu create a instance of Breadcrumbs.

use Naucon\Breadcrumbs\Breadcrumbs;
$breadcrumbs = new Breadcrumbs();

Afterwards you can add breadcrumbs to that instance with the method add(). This the first parameter a title of the breadcrumb must be defined. With the second parameter a URL can be defined (optional).

$breadcrumbs->add('home', '/home/');
$breadcrumbs->add('profile', '/profile/');
$breadcrumbs->add('address');

Another way is with the fluent interface.

$breadcrumbs->add('home', '/home/');
    ->add('profile', '/profile/');
    ->add('address');

With foreach you can iterate through the added breadcrumbs. The value is a instance of Breadcrumb which have methodes to access breadcrumb title and URL. The breadcrumbs a in the order they are added (FIFO).

foreach ($breadcrumbs as $breadcrumb)
{
    if ($breadcrumb->hasUrl()) {
        echo '<a href="' . $breadcrumb->getUrl() . '">' . $breadcrumb->getTitle() . '</a>';
    } else {
        echo $breadcrumb->getTitle();
    }
}

The output of the example would be

<a href="/home/">home</a><a href="/profile/">profile</a>address

To reverse the order of the breadcrumb use the method getReverseIterator(). The breadcrumbs will be interated in the reverse order they are added (LIFO).

$breadcrumbsIterator = $breadcrumbs->getReverseIterator();
foreach ($breadcrumbsIterator as $breadcrumb)
{
    if ($breadcrumb->hasUrl()) {
        echo '<a href="' . $breadcrumb->getUrl() . '">' . $breadcrumb->getTitle() . '</a>';
    } else {
        echo $breadcrumb->getTitle();
    }
}

The output of the example would be

address<a href="/profile/">profile</a><a href="/home/">home</a>

Breadcrumb Handler

Breadcrumb items are collected in a instance of BreadcrumbCollection. To read and write into the collection a handler is used. The default handler is BreadcrumbHandlerNull which only adds or remove entries to the collection.

In some use cases the breadcrumb entries must persist between page loads. In this cases the BreadcrumbHandlerSession can be set. The Handler will read and write into the $_SESSION variable.

// start session
session_start();

...

use Naucon\Breadcrumbs\Breadcrumbs;
use Naucon\Breadcrumbs\Handler\BreadcrumbHandlerSession;
$breadcrumbs = new Breadcrumbs();
$breadcrumbs->setBreadcrumbHandler(new BreadcrumbHandlerSession());

...

// add breadcrumb entry
$breadcrumbs->add('Home', '/home/');

...

// close session
session_write_close();

Make sure that you started and close session befor and after you use the breadcrumb.

Breadcrumb helper

With the breadcrumb helper a instance of Breadcrumbs can be rendered in HTML Markup.

To use the helper create a instance of BreadcrumbsHelper and give the constructor a instance of Breadcrumbs.

use Naucon\Breadcrumbs\Helper\BreadcrumbsHelper;
$breadcrumbsHelper = new BreadcrumbsHelper($breadcrumbs);

With the method render() the html markup will be generated an returned.

echo $breadcrumbsHelper->render();

// <a href="/home/">home</a><a href="/profile/">profile</a>address

With the method setSeparator() a separator between the breadcrumbs can be defined.

$breadcrumbsHelper->setSeparator(' / ');
echo $breadcrumbsHelper->render();

// <a href="/home/">home</a> / <a href="/profile/">profile</a> / address

With the method setReverse() the order of the breadcrumbs can be reversed.

$breadcrumbsHelper->setReversed(); // or $breadcrumbsHelper->setReversed(true);
echo $breadcrumbsHelper->render();

// address / <a href="/profile/">profile</a> / <a href="/home/">home</a>

With the method setSkipLinks() links will be skipped in render.

$breadcrumbsHelper->setSkipLinks(); // or $breadcrumbsHelper->setSkipLinks(true);
echo $breadcrumbsHelper->render();

// home / profile / home

With the method setTag() a html element can be set surround the breadcrumb. The following html element are supported: span, div, li, ul, ol

Example with span element:

$breadcrumbsHelper->setTag('span');
$breadcrumbsHelper->setSeparator(' / ');
echo $breadcrumbsHelper->render();

// <span><a href="/home/">home</a></span> / <span><a href="/profile/">profile</a></span> / <span>address</span>

Example with div element:

$breadcrumbsHelper->setTag('div');
$breadcrumbsHelper->setSeparator(' / ');
echo $breadcrumbsHelper->render();

// <div><a href="/home/">home</a></div> / <div><a href="/profile/">profile</a></div> / <div>address</div>

Example with li element:

$breadcrumbsHelper->setTag('div');
$breadcrumbsHelper->setSeparator(' / ');
echo $breadcrumbsHelper->render();

// <li><a href="/home/">home</a></li> / <li><a href="/profile/">profile</a></li> / <li>address</li>

When using the tag ul or ol also the attributes id, class, style can be defined.

Example with ul element:

$breadcrumbsHelper->setTag('ul');
$breadcrumbsHelper->setOptions(array('id' => 'breadcrumb', 'class' => 'breadcrumbs'));
echo $breadcrumbsHelper->render();

// <ul id="breadcrumb" class="breadcrumbs"><li><a href="/home/">home</a></li><li><a href="/profile/">profile</a></li><li>address</li></ul>

Example with ol element:

$breadcrumbsHelper->setTag('ol');
$breadcrumbsHelper->setOptions(array('id' => 'breadcrumb', 'class' => 'breadcrumbs'));
echo $breadcrumbsHelper->render();

// <ol id="breadcrumb" class="breadcrumbs"><li><a href="/home/">home</a></li><li><a href="/profile/">profile</a></li><li>address</li></ol>

Breadcrumb Smarty Plugin

When using the Smarty Template Engine the breadcrumb helper can be integrated with a smarty plugin.

First have hook up the smarty plugins to smarty.

$smartyObject->plugins_dir[] = PATH_LIBRARY . 'vendor/naucon/Breadcrumbs/SmartyPlugins';

Next assign the instance of Breadcrumbs class to smarty.

$smarty->assign('breadcrumbs', $breadcrumbs);

Then add the plugin to the template.

{ncbreadcrumbs from=$breadcrumbs tag='span' separator=' / '}

or

{ncbreadcrumbs from=$breadcrumbs tag='div' separator=' / '}

or

{ncbreadcrumbs from=$breadcrumbs tag='ul' id='breadcrumb' class='breadcrumbs'}

or

{ncbreadcrumbs from=$breadcrumbs tag='ol' id='breadcrumb' class='breadcrumbs'}

or

{ncbreadcrumbs from=$breadcrumbs tag='ol' id='breadcrumb' class='breadcrumbs' reverse=true}

or

{ncbreadcrumbs from=$breadcrumbs separator=' / ' skip-links=true}

The smarty plugin supports the following parameters


All versions of breadcrumbs with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
naucon/utility Version ~1.1
naucon/htmlbuilder Version ~1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package naucon/breadcrumbs contains the following files

Loading the files please wait ....