Creitive\Breadcrumbs\Breadcrumbs::addCrumb PHP Method

addCrumb() public method

Adds a crumb to the internal array.
public addCrumb ( string $name = '', string $href = '', boolean $hrefIsFullUrl = false )
$name string The name of this breadcrumb, which will be seen by the users.
$href string If this parameter begins with a forward slash, it will be treated as a full URL, and the `$hrefIsFullUrl` parameter will be forced to `true`, regardless of its value.
$hrefIsFullUrl boolean Whether the `$href` argument is a full URL or just a segment. The difference is that segments will be built upon previous breadcrumbs, while full URLs will be returned as they are inputted. This can be automatically forced to `true`, depending on the `$href` argument - read its description for details.
    public function addCrumb($name = '', $href = '', $hrefIsFullUrl = false)
    {
        if (mb_substr($href, 0, 1) === '/') {
            $length = mb_strlen($href);
            $href = mb_substr($href, 1, $length - 1);
            $this->addCrumb($name, $href, true);
        } elseif (mb_substr($href, 0, 7) === 'http://' && !$hrefIsFullUrl) {
            $this->addCrumb($name, $href, true);
        } elseif (mb_substr($href, 0, 8) === 'https://' && !$hrefIsFullUrl) {
            $this->addCrumb($name, $href, true);
        } else {
            $crumb = array('name' => $name, 'href' => $href, 'hrefIsFullUrl' => $hrefIsFullUrl);
            $this->breadcrumbs[] = $crumb;
        }
        return $this;
    }

Usage Example

 /**
  * Tests whether `Breadcrumbs::isEmpty()` works correctly.
  */
 public function testIsEmpty()
 {
     $b = new Breadcrumbs();
     $this->assertTrue($b->isEmpty());
     $b->addCrumb('foo', 'bar');
     $this->assertFalse($b->isEmpty());
 }
All Usage Examples Of Creitive\Breadcrumbs\Breadcrumbs::addCrumb