weixin_33743703 2013-02-15 17:31 采纳率: 0%
浏览 27

cakephp addCrumb HTML帮助器

I'm trying to use the breadcrumb functionality of the Html Helper in a Cake php application to create a breadcrumb trail. I followed the way they said to do it on the manual (scroll all the way to the bottom to see it), but the problem I am facing is that, when the view is loaded via Ajax (by using jquery's .load() function for example), my breadcrumb is not displayed. I put this in my view:

<?php echo $this->Html->addCrumb('Users', '/users'); ?>

And this in my layout:

<?php echo $this->Html->getCrumbs(' >> ', 'Home'); ?>

But nothing is displayed. When the view is not loaded via Ajax, everything is fine. Can anybody tell me why this is happening please?

Thank you

  • 写回答

1条回答 默认 最新

  • from.. 2013-02-16 09:23
    关注

    You could output the crumbs in the view again, hidden, and then after .load() append them to the crumbs in your layout. You won't be able to do it otherwise. The "layout" crumbs have already been rendered and won't render again if you are using load() to inject content.

    Some sample code to give you an idea of how I'd do it:

    // layout
    echo '<div class="crumbs">' . $this->Html->getCrumbs() . '</div>';
    echo '<div class="content"><!-- AJAX content goes here--></div>';
    
    // view
    $this->Html->addCrumb('My Page');
    echo '<div class="hiddenCrumbTrail">' . $this->Html->getCrumbs() . '</div>';
    echo 'Here is my page content';
    
    // js
    $(function() { 
        $('.content').load('/controller/action'); // load content
        $('.crumbs').empty(); // remove existing
        $('.crumbs').append($('.hiddenCrumbTrail')); // append with updated
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥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