Breadcrumbs |
[eluser]KeyStroke[/eluser]
I'm trying to include flexible and automated breadcrumbs in my application, but I have no idea where to start. I've found this thread and this one also, but both seem too complicated, and don't offer enough customization. Is there a better library that can handle this? If not, will at least someone help me in nailing the concept of breadcrumbs within CodeIgniter? Appreciate your help ![]()
[eluser]xwero[/eluser]
The easiest solution is a db table that holds all your links with their hierarchy, and you fetch the current link which builds the crumb trail.
[eluser]KeyStroke[/eluser]
I've thought of that, but the problem is that my breadcrumb is dynamic. Meaning, it could be : Home > cars > topic or Home > games > topic Just like this forum's breadcrumb. How would that work?
[eluser]richthegeek[/eluser]
all you need is a breadcrumb array (or write a helper) In the CI index.php, add Code: $breadcrumb = new array( '/'=>'Home' ); Then for each seperate level of the site add another key to the breadcrumb array, something like Code: class Faq extends Controller { That sort of thing. In your view, you can then call another view called "breadcrumb.php", which loops through this array creating a breadcrumb trail. If you had a helper, you could do easier stuff like: Code: $this->breadcrumb->add( URL, name ); Code: $this->breadcrumb->draw( [return] );
[eluser]xwero[/eluser]
It doesn't matter how you name the links, they should all have a unique number. Or another way you could go is to identify the trail based on the uri_string.
[eluser]Pascal Kriete[/eluser]
[quote author="xwero" date="1208281002"]It doesn't matter how you name the links, they should all have a unique number. Or another way you could go is to identify the trail based on the uri_string.[/quote] Which could look something like this (using modules here, but it would be easy enough to revert to folders): Code: function from_path($slug = '') Where the _output function displays it any way you want. In my case, I just add it to the ci output buffer.
[eluser]KeyStroke[/eluser]
Thanks guys. But to be honest, those examples kind of confused me. Maybe because I can't see the implementation or something, but it wasn't clear for me. Maybe there's another way around? 8-/
[eluser]frenzal[/eluser]
There are too many ways to do this, it heavily depends on where you get your page data from imho
[eluser]Pascal Kriete[/eluser]
Quite correct, in some instances you may even have to iterate through the database (not fun). Can you give an example of the kind of breadcrumb you need. What part wasn't clear to you? What kind of application do you want to use it in?
[eluser]adamp1[/eluser]
I use a manual method to create breadcrumbs becasue otherwise its so hard to get something worth while out of the uri_string alone. Also it means you can have complex breadcrumbs. Just use an array to store the crumbs and then as said above a display method. Code: <?php That's my library I use. So just save that as a file in the libraries folder and use the functions in there. Due to the way its made you can build the trail up as you go along. |
Welcome Guest, Not a member yet? Register Sign In |