dev-master
9999999-devA simple breadcrumb generator for Laravel 4
MIT
The Requires
- php >=5.3.0
- illuminate/support 4.x
by Marnix Janssen
A simple breadcrumb generator for Laravel 4
** If you have problems running setSeperator (typo'd) after update, I changed the function name to setSeperator., (*1)
A small and easy customizable breadcrumb generator for Laravel 4., (*2)
Edit your .json file and add the following line to your "require", (*3)
"mj/breadcrumb": "dev-master"
, (*4)
After this run the composer update
to update your framework and get the breadcrumb class loaded into your files., (*5)
Open app.php in your config folder, (*6)
Add the line 'Mj\Breadcrumb\BreadcrumbServiceProvider'
to the providers array., (*7)
To make use of the Facade that comes with Laravel 4, make sure you register the alias in the file 'app/config/app.php'., (*8)
Like this: 'Breadcrumb' => 'Mj\Breadcrumb\Facades\breadcrumb'
, (*9)
To create breadcrumbs use the following code:, (*10)
Breadcrumb::addbreadcrumb('linkname', 'url');
, (*11)
You can add multiple breadcrumbs by repeating the code above., (*12)
To set an seperator you can use:, (*13)
Breadcrumb::setSeparator('yourseperator')
, (*14)
At last send your breadcrumbs to your template (or just generate them) with the following command:, (*15)
Breadcrumb::generate()
, (*16)
Note: Use real url's (like /this/page) and not Laravel's URL helper. Not setting a URL at all will also work., (*17)
//Controller public function page() { //Those are required to set some breadcrumbs first. Breadcrumb::addBreadcrumb('home', '/'); Breadcrumb::addBreadcrumb('some page', '/some-page'); Breadcrumb::addBreadcrumb('last piece'); //Does not need a url because it's the last breadcrumb segment Breadcrumb::setSeparator('/'); //Set some seperator you think is nicest (not required) $data = array( 'breadcrumbs' => Breadcrumb::generate() //Breadcrumbs UL is generated and stored in an array. ) //return the view with the $data array to use it in the view return View::make('some/page', $data); } //View {{$breadcrumbs}} // -> UL with list-items with the links :)
A simple breadcrumb generator for Laravel 4
MIT