开发者

Approach including a Footer in every page using php

开发者 https://www.devze.com 2023-02-16 20:48 出处:网络
Hey all. i was wondering what is the best practice to include a footer in all of my pages. i mean i have about 1000 of them. should i use the

Hey all. i was wondering what is the best practice to include a footer in all of my pages. i mean i have about 1000 of them. should i use the php "include" function: include 'static_footer.html' 开发者_如何转开发or is it a bad practice ?


If you have 1000 .php file pages, you may want to look into using an Model-View-Controller solution (like storing the page information in a database and using Code Igniter or something similar to display the information), or a Content Management System of some description.

But, as far as I know, your best bet would be to use the include() function.

include 'footer.php';


There is always the option of using the auto_append_file directive in php.ini to automatically include a file rather than modifying every single page


I believe it is perfectly fine to use an include function. This way, you'll be mimicking a sort of template engine, and it is a good way to avoid using the same code over and over again.


I would say that is definitely a good idea, as it helps adhere to the DRY principle.

Depending on your scenario, it might be worth looking at some php_value setting in a .htaccess file (if you're in a web environment). You can auto_prepend a file to the output, which would save you adding an include statement to every file. This might not suit your needs, but for simple applications, it can.

0

精彩评论

暂无评论...
验证码 换一张
取 消