dopii22884 2014-05-26 09:21
浏览 24
已采纳

如何在CakePHP中制作或调用侧边栏

I have such type of code in view, add.ctp file in Cake PHP.

<div id="container">
   <div id="content">
      ------------------
   </div>
   <div id="sidebar">
   ----------------
   </div>
</div>

Now in Layout, in default.ctp file, we access this code by this line.

<?php echo $this->fetch('content'); ?>

I have sidebar in each and every view file, and if I need some changes then I will go in each and every file and then change.

Now My Question is that, can I made a file in layout like sidebar.ctp or any thing else that I just call this file in my view. If I can, then how I will made such type of file.

  • 写回答

2条回答 默认 最新

  • dongyou5068 2014-05-26 09:29
    关注

    You could do it with include or elements like this

    <?php echo $this->element('sidebar'); ?>
    

    With the element, you make the sidebar.ctp file in the View/Elements/ folder.
    Check for more information: Cakephp 2 Elements

    The other way is with include (not my choice, but another way to accomplish it)

    <?php include('../View/Layouts/sidebar.ctp'); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?