Welcome Guest, Not a member yet? Register   Sign In
Custom Breadcrumbs
#1

[eluser]frankthetank[/eluser]
Hi everyone,

I would like to include breadcrumbs to my site without using the Breadcrumbs Library which I found in the search since it simply parses a url (e.a. /forums/newtopic would be shown as Forums > Newtopic) while I have my site divided over various controllers.

I see that CodeIgniter uses breadcrumbing the way I would like as well, for example using different controllers =>

www.site.nu/
Breadcrumb=> Home

www.site.nu/viewforum/1
Breadcrumb=> Home > ForumTitle

www.site.nu/viewthread/2
Breadcrumb=> Home > ForumTitle > ForumThread

Basically, no url parsing because of different controllers. How might this be possible in CI? It sounds difficult since users can hit the back button and such and screw up breadcrumbs.

Hope you guys have a tip,
Regards Frank
#2

[eluser]esra[/eluser]
Holger Lampe's breadcrumb library works well when working with multiple controllers.
#3

[eluser]xwero[/eluser]
For static urls you can set up an config file and for variable urls you could add a breadcrumb method to get the url and the linkname in each model so you have not to much dependencies.
And you then make a helper to put the links you gathered in your controller in a view file.

Following your example you would have something like
Code:
// config
$config['bc_home'] = array('Home','http://www.site.nu');
//controller
class Page extends Controller
{
   private $breadcrumb;
  
   function Page()
   {
     $breadcrumb[] = $this->config->item('bc_home');
   }

   function viewforum()
   {
      $this->breadcrumb[] = $this->forummodel->breadcrumb('forum',$this->uri->segment(2));
      $data['breadcrumb'] = $this->breadcrumb;
   }

   function viewthread()
   {
      $this->breadcrumb[] = $this->forummodel->breadcrumb('thread',$this->uri->segment(2));
      $data['breadcrumb'] = $this->breadcrumb;
   }
}
// view
<?php create_breadcrumb($breadcrumb); ?>
#4

[eluser]frankthetank[/eluser]
Thanks for the tips however can you show me how this might work with different controllers, not functions within the same controller? And Holger Lampe's does not work for different controllers, but only with url's that are built as such => 1/2/3 => bc: 1 > 2 > 3 , while I have, /viewforum/1 bc: viewforum, /viewthread/2 bc: viewforum > viewhtread

edit:
Also I'd rather not have it static, would mess up clean code.
#5

[eluser]xwero[/eluser]
for different controllers it could be something like this
Code:
//controller 1
class Page extends Controller
{
   private $breadcrumb;
  
   function Page()
   {
     $this->breadcrumb[] = $this->config->item('bc_home');
     $this->breadcrumb[] = $this->config->item('bc_page');
   }

   function viewforum()
   {
      $this->breadcrumb[] = $this->forummodel->breadcrumb('forum',$this->uri->segment(2));
      $data['breadcrumb'] = $this->breadcrumb;
   }

   function viewthread()
   {
      $this->breadcrumb[] = $this->forummodel->breadcrumb('thread',$this->uri->segment(2));
      $data['breadcrumb'] = $this->breadcrumb;
   }
}
//controller2
class Page2 extends Controller
{
   private $breadcrumb;
  
   function Page2()
   {
     $this->breadcrumb[] = $this->config->item('bc_home');
     $this->breadcrumb[] = $this->config->item('bc_page2');
   }

   function viewme()
   {
      $this->breadcrumb[] = $this->personmodel->breadcrumb('me',$this->uri->segment(2));
      $data['breadcrumb'] = $this->breadcrumb;
   }

   function viewyou()
   {
      $this->breadcrumb[] = $this->personmodel->breadcrumb('you',$this->uri->segment(2));
      $data['breadcrumb'] = $this->breadcrumb;
   }
}
#6

[eluser]frankthetank[/eluser]
But thats in a static environment.

The problem is, I am thinking of producing a class that stores the breadcrumbs on all pages however the problem then lies in resetting the breadcrumbs whenever a user clicks on page back and setting the breadcrumbs to the correct location.

controller1 => addBreadcrumb(link,title); bc: controller1
controller2 => addBreadcrumb(link,title); bc: controller1 > controller 2

* User clicks on page back, now it has to show controller1 *

It gets even more complicated when the user jumps back from controller1, controller2, controller3 to controller1.

I just cant figure out an easy idea how to do this. Static is the easiest method but its also the ugliest from a programming viewpoint.
#7

[eluser]xwero[/eluser]
I'm not sure what do you mean by static. Do you have controller methods that you generate dynamically?

But if understand your last example correctly you don't want a breadcrumb for the hierarchy of the site but for the user clicked history?

I guess you could do that with a session variable that checks the position of the page where the request leads to and removes everything behind it.
#8

[eluser]frankthetank[/eluser]
Well, basically iam building a forum similar to CI forums. I also need the same breadcrumb which is on the top of the page. Meaning, using different controllers that do make up a hierarchy.

For example:

1st index page => indexforum
2nd view a forum => viewforum
3rd view a thread => viewthread

These are three different controllers but from 1 to 3 make up a hierarchy. However, how do I turn this into breadcrumbs without statically saying ['index'] = www.site.nu, ['forum'] = www.site.nu/viewforum.
#9

[eluser]Pygon[/eluser]
Any way you slice this, it's going to be rather compicated and require static naming (bad for a dynamic forum) or SQL modification.

For example, when viewing a thread, you'll also need to query the category name that thread is in (not terribly complicated, just left join on the category_id if you have a proper db structure), then write out

Home(static) -> category_title -> thread_title

From there, it depends on how well your db is designed in terms of your dynamic pages and what-not.

Like I said, probably going to get complex.

-------
regarding your recent post...

You're probably not going to. You will still need static locations of your controllers.
#10

[eluser]frankthetank[/eluser]
So it is safe to say that CI has done the same thing? Too bad though, wish there was a good class that would handle this properly.




Theme © iAndrew 2016 - Forum software by © MyBB