duanhun3273 2011-08-03 17:17
浏览 45
已采纳

Codeigniter两个param数据库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 breadcrumb control structure on the view, and not what I want.

  • 写回答

3条回答 默认 最新

  • drcj64241 2011-08-03 18:23
    关注

    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?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题