简体   繁体   中英

cakephp Views and layout

I designed a footer in the default.ctp layout

 <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'); ?> <?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?

I am new to cakePHP , so might sound like a foolish question.

When creating a footer like that, it should not be in your default.ctp layout.

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)
  • or src/Template/Element/footer.ctp file (when using CakePHP 3.x).

Then in both your default.ctp layout and your purchases.ctp layout, simply embed it:

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

That way, whenever you edit anything in your footer, it will edit in all the layouts that use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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