Download the PHP package happydemon/elements without Composer
On this page you can find all versions of the php package happydemon/elements. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download happydemon/elements
More information about happydemon/elements
Files in happydemon/elements
Package elements
Short Description A Kohana module to help with building HTML navigation menus and breadcrumbs
License MIT
Homepage https://github.com/happyDemon/elements
Informations about the package elements
HTML Navigation Module for Kohana 3.3
Simplify rendering, building and maintenance of simple, dynamic standardised navigation menus and breadcrumbs. Instead of ...
... we do this:
As you can see the first item uses an url property, as the original Kohana-menu module required, while the second item uses a route property.
The route property was added to make use of Kohana's own routing system and use reverse routing, making it easier to check if the link is currently active.
I do recomend defining routes for every controller's action you have in your project.
Installation
Place the files in your modules directory.
As a Git submodule:
As a Composer dependency
Copy MODPATH.elements/config/navigation/navbar.php
into APPPATH/config/navigation/navbar.php
and customize
Activate the module in bootstrap.php
.
Example use case
A WordPress type blog might have...
- Public main navigation menu
- Public footer menu
- Admin-only menu on the public pages, when admin is logged in
- Admin-only menu on the administrator interface
Normally, you'd build HTML views with ul
and li
elements and then write some PHP to highlight the active link. This is
difficult to maintain (DRY) and too much hassle (not to mention ugly).
Instead, describe your (standardised) menus in configuration files and have Kohana do the heavy lifting.
The same goes for breadcrumbs, you might need them for:
- Administration panel
- Forum
- Catalogs
and could have the same structure you'd use for your menu's
What this fork offers over Kohana-menu
Kohana-menu has a specific job and does it well, I personally also needed a way to manage my breadcrumbs for certain areas of the site.
Since my breadcrumbs contain the same data structure as my menu's (and many could share 1 config file), I decided to expand on this module so I could use it for both ends.
Basics
You define your menus in Kohana configuration files (see config/navigation/navbar.php). Then, in your (main) controller (or template), you construct a new Element object, set the active link and render it in your template. Done.
Echo menu output in your template (using the included twitter bootstrap template)
and output the breadcrumb wherever you want (we'll use the bootstrap styling)
You might wish to instantiate the menu in your main controller, since this gives you a way to interact with the Element object before it's rendered.
Config files
You can use different config files by setting the factory's $config
parameter.
Example: Load menu configuration based on user role
Marking the current menu item
Use set_current()
to mark the current menu item in your controller if you're not making use of routes
The parameter of set_current()
is the URL value of the respective item or its (numeric) array key.
However, if you've defined a 'route' property in the item it can be auto-detected if you define all your routes using Route::set in your bootstrap.php or init.php's
Hard-set the active breadcrumb item
On certain pages you'd like to show a dynamic active breadcrumb item (the last one down the tree) to clearify which action if being done.
You can do this by calling last_item
on your Element
object and defining what you'd want to be rendered instead of the default text that was defined in your config file:
Documentation
The code is mostly commented, a user guide is on it's way with more examples.
Licence
The Kohana module started out as a fork of Anroot's Kohana-menu, which in turn is a fork of the original Kohana Menu module by Bastian Bräu, but is now independently developed under the MIT licence.