开发者

Codeigniter two param database breadcrumb

I am using the php framework codeigniter.

I am attempting to create a here is an example:

  • animals/feline/lion
  • animals/feline/tiger
  • animals/feline/snow-leopard
  • animals/canine/wolf
  • animals/canine/coyote

Where both genus (feline) and species (lion) are both retrieved from a database and animals is a controller. I have models that place genus and species in their respective arrays. I also wish to have views for each step along the breadcrumb as follows:

  • animals
  • animals/feline
  • animals/canine

Any help would be greatly appreciated. I just looked at autocrumb and all it was as for displaying the br开发者_如何学Pythoneadcrumb control structure on the view, and not what I want.


I'd use URi routing., as another approach than __remap(), which is better, but I just wanted to give another choice

$route['animals/(:any)/(:any)'] = "animals/method/$1/$2";

In you animals controller you have

 function method($genus,$species)
 {

   $data['breadcrumb'] = 'animals -> '.$genus.' -> '.$species.
   $this->load->view('breadcrumb', $data);
   $this->load->view('animals/'.$genus.'/'.$species);
 }

view breadcrumb.php:

<div id="breadcrumb">
<?php echo $breadcrumb;?>  <!-- Display: animals -> feline -> lion -->
</div>

View folder contains:

breadcrumb.php
animals /
          feline /
                   feline.php
          canine/  
                   wolf.php

Is this what you were looking for?

EDIT after comments:

SO looks like we've mistaken what you wanted. If you're retrieving those variables from DB, then you could do like this:

function index()
{
  $this->load->view('animals/index');
}

function genus($genus)
{
  $data['genus_data'] = $this->your_model->load_genus_data($genus);
  $this->load->view('animals/genus',$data);
}
function species($genus,$species)
{
 $data['genus_data'] = $this->your_model->load_genus_data($genus);
 $data['species_data'] = $this->your_model->load_species_data($species);
 $this->load->view('animal/genusspecies',$data);
}

In your view genus.php (in folder animal):

<?php $genus_data->name;?> is an animal that...Here's a pic in its habitat.

In your view genusspecies.php (in folder animal):

<?php $species_data->name;?> is a species of genus <?php $genus_data->name;?>....

all those might be html snippets you load from database;

Your routing might look like this then:

$route['animal'] = "animal";
$route['animal/(:any)'] = "animal/genus/$1";
$route['animal/(:any)/(:any)'] = "animal/species/$1/$2";

If I were you, I'll go about this way. Do I got it better or am I still wrong somewhere?


Add a _remap() function to your animals controller

if($this->uri->segment(3) === FALSE)
{
    $this->genus();
}
else
{
    $this->species();
}

This assumes you have a method called genus() and a method called species()

_remap() docs: http://codeigniter.com/user_guide/general/controllers.html#remapping

URI Library docs: http://codeigniter.com/user_guide/libraries/uri.html


redirect('animals/' . $genus . '/' . $species);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜