cakephp视图和布局


cakephp Views and layout

我在default.ctp布局中设计了一个页脚

 <div class="container-fluid footer-wrapper hidden-xs hidden-sm " style="margin-top:50px;">
     <div class = "row" style="padding-top:50px;">
        <div class="col-md-4">
some text 
</div></div></div>

所以现在我有了另一个文件purchase.ctp,所以只写<?php echo $this->Element('footer'); ?>,它会实现从default.ctp到purchases.ctp的页脚吗?还是我必须对default.ctp页脚进行一些更改或在那里写一些代码?

我是cakeHP的新手,所以这听起来可能是个愚蠢的问题。

创建这样的页脚时,它不应该在default.ctp布局中。

为了在多个布局中重复使用页脚,请创建一个新元素:

  • app/View/Elements/footer.ctp文件(使用CakePHP 2.x时)
  • src/Template/Element/footer.ctp文件(当使用CakePHP 3.x时)

然后在default.ctp布局和purchases.ctp布局中,只需嵌入它:

echo $this->element('footer');

这样,每当你在页脚中编辑任何内容时,它都会在所有使用它的布局中进行编辑。