[eluser]iive[/eluser]
The solution that I am doing is :
Create a Breadcrumb class and a BreadcrumbNode class. Breadcrumb class will have a function called addNode() which accept BreadcrumbNode and a function called build() to build out the whole breadcrumb.
I use a config file to define all the static page in an array and then pass the whole array into Breadcrumb class to build the tree.
BreadcrumbNode take arguements as:
BreadcrumbNode($level, $parent_id, $node_id, $indentifier, $href, $label );
It looks something similiar to:
Code:
$node_array = array();
$node_array[] = new BreadcrumbNode(0,NULL,0,"home", "home", "Home");
$node_array[] = new BreadcrumbNode(1,0,1,"games", "game", "Games");
$node_array[] = new BreadcrumbNode(1,0,2,"member_page", "user", "My Account");
Inside controller,
Code:
class Game extends Controller {
function Game()
{
parent::Controller();
$this->load->library('breadcrumb');
}
function index()
{
// Will produce Home >> Games
echo $this->breadcrumb->render("games"));
}
function play(){
//Get game name dynamically from URI
$game_name = $this->uri->segment(3);
// Add new BreadcrumbNode dynamically by specify the new level and parent id
// set the third arguement to null so that Breadcrumb class can generate
// next increment id
$this->breadcrumb->addNode(new BreadcrumbNode(2,1,null,"games-play","game/play/".$game_name, $game_name));
// Generate the breadcrumb
// will produce Home >> Games >> Game Name
echo $this->breadcrumb->render("games-play");
}
}
I hope you get what I tried to mean. I am not sure whether this is a good way to work with breadcrumb. I have searched through the forums, but I couldn't get a good solution for this. So I come out these 2 classes to accomplish my task.