Welcome Guest, Not a member yet? Register   Sign In
How to creating a "path" for websites like "you are here"
#1

[eluser]uk81[/eluser]
Hi.

I want to create a path for a website like often seen on websites:
"You are here: home > foo > bar"

And I wanted to know if there is a easy way (maybe someone has done this before) to create such a path with CI.

My problem is, that I have several controllers, views, a library (normal way, if you work with CI) and every time one controller is called, which worked with my library, with several views and models, parse the data and at the end it will all put together in one big main-template to view it to the user.

The data and the calls are shared over the several classes I use/call. So it is not easy to just give one string one function to parse it.
I have several categories (in my website) and the user can view a service via one or more categories. He can navigate via a view ways also with subcategories.
So I have to know the parent category, the actual category and the service name and so on.

And I thought there is maybe a easy way. Maybe something like store one array in a library (or somewhere else) where every controller, function, library I call put a info in it, which I can parse afterwards into a path like shown above.

The other (complicated way, I donĀ“t wanted to go) is to write an extra function for every controller which get the relevant data from the database, get all data step by step and parse the path self. This is in my situation a little bit complex, because there are so many variable ways to go in my application.

This would also be a feature request (if there is nothing in code igniter). Just give (maybe with a special controller function) a string back to CodeIgniter which is stored in an array. And with one CI-function call the programmer get a string parsed like: "You are here: parameter 1 > parameter 2 > parameter 3"

Thanks guys.
#2

[eluser]Pascal Kriete[/eluser]
You will need to grab the category, subcategory, and item name form the database and then generate a breadcrumb using that information. There are some useful breadcrumb libraries out there (should be in the wiki) that might make this process easier.

I would probably write a model function that does most of the work, tack on the homepage and send it off to the library. You might even be able to use the url segments. Get creative with it, there many ways to tackle this.

CI has no way of knowing how your site is structured or how your data is related, so there is no way to abstract this to a library that works for everyone.
#3

[eluser]uk81[/eluser]
Hej.

Thanks for your fast answer!
Ok, I think I have to write it by myself. Wink

But thanks for the suggestions with the breadcrumb tools.

But I have another question. By thinking about how to solve this problem I had an idea in my brain.
For example: I have one array in my library which stores the data for the breadcrumbs. When I now call (e.g.) a function in the library 4 times and every time I also call a special function for put one breadcrumb in my library-array.
Is the library (which I have instanciated in my controller) one instance which stores all data from all calls? So that I can call at the end one function createBreadcrumbs() and it parses my array and returns it?
Also when I work with several controllers, models and so on ... ?

Or work CI in that way, that there is one instance for every class (when I instanciate the library) and when I put one breadcrumb in the library-array, there is one array for each class (one instance with one array for every controller, model...)?
#4

[eluser]Pascal Kriete[/eluser]
Everything is a singleton unless you create your own instances. So whenever you use $this->breadcrumb, you are referring to the same object.

So calling add_crumb multiple times in this library will work as expected:
Code:
<?php
class Breadcrumb {
    var $crumbs = array();

    function add_crumb($url, $title = '')
    {
        $this->crumbs[$url] = $title;
    }
    
    function generate()
    {
        // do something with $this->crumbs
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB