PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] What is better way to load header and footer in CakePHP?

 April 22, 2022     cakephp, cakephp-2.3, php, templates     No comments   

Issue

I am getting my foot wet with CakePHP and wondering what is better to load views. I tried searching but could not find satisfying answer for this small question. If I have to load header and footer along with content, what should be better approach :

1) Using $this->fetch("header") in view.ctp

or 2) I don't know how is it possible but, loading different views one after another from controller like we do in CodeIgniter ($this->load->view("header")).


Solution

As mentioned by user2076809, you'll probably want to use elements for this purpose, to keep things DRY: book.cakephp.org/2.0/en/views.html#elements.

Be aware though that Cake uses layouts (http://book.cakephp.org/2.0/en/views.html#layouts) to handle the header and footer by default, so take a look at app/View/Layouts/default.ctp and make sure you don't have redundant code there (for example, it has the <head> tag with all the default CSS includes).



Answered By - Erebus
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing