do-it-yourself universal header/footer.php

后端 未结 3 661
情歌与酒
情歌与酒 2021-01-25 10:54

I wanna make universal header/footer include files.
Universal here means to be applicable in files on any directory level without need to add “../” at any deeper level when

3条回答
  •  抹茶落季
    2021-01-25 11:45

    Calling css images and the such uses ../ while programatically correct is bad form. You should always use absolute paths /css/style.css /images/image.png /js/script.js etc...

    I usually define the application directory with a constant for headers and footers.

    define('APPDIR', $_SERVER['DOCUMENT_ROOT']);
    

    Makes it a bit easier to include other files without all having to write out all variable for the doc root over and over.

    Though in my opinion everything is moving towards frameworks, you should really consider sung Symfony, Codeigniter or the like. If it's a 3 page deal, do it straight up php but if you're doing an all out app and it's new development, you do yourself a disservice by not using a framework.

提交回复
热议问题