简体   繁体   English

cakephp视图和布局

[英]cakephp Views and layout

I designed a footer in the default.ctp 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>

and so and now I have a another file purchase.ctp , so just writing <?php echo $this->Element('footer'); ?> 这样,现在我有了另一个文件Purchase.ctp,因此只需编写<?php echo $this->Element('footer'); ?> <?php echo $this->Element('footer'); ?> , will it implement the footer from default.ctp to purchases.ctp or do i have to make some changes to the default.ctp footer or write some code there? <?php echo $this->Element('footer'); ?> ,它将实现从default.ctp到Purchases.ctp的页脚,还是我必须对default.ctp页脚进行一些更改或在其中编写一些代码?

I am new to cakePHP , so might sound like a foolish question. 我是CakePHP的新手,所以听起来像是一个愚蠢的问题。

When creating a footer like that, it should not be in your default.ctp layout. 当创建这样的页脚时,它不应位于您的default.ctp布局中。

In order to re-use the footer on multiple layouts, create a new element: 为了在多个布局上重复使用页脚,请创建一个新元素:

  • app/View/Elements/footer.ctp file (when using CakePHP 2.x) app/View/Elements/footer.ctp文件(使用CakePHP 2.x时)
  • or src/Template/Element/footer.ctp file (when using CakePHP 3.x). src/Template/Element/footer.ctp文件(使用CakePHP 3.x时)。

Then in both your default.ctp layout and your purchases.ctp layout, simply embed it: 然后在这两个你default.ctp布局和purchases.ctp布局,只需将它嵌入:

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

That way, whenever you edit anything in your footer, it will edit in all the layouts that use it. 这样,无论何时在页脚中进行任何编辑,它都将在使用它的所有布局中进行编辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM