calling include from an included file

后端 未结 3 445
攒了一身酷
攒了一身酷 2020-12-14 16:45

So, examining this directory structure

  • /include_one.php
  • /include_two.php
  • /directory/main_file.php

A

3条回答
  •  我在风中等你
    2020-12-14 17:12

    I am using this code:

    if(!isset($TO_HOME_DIR)) $TO_HOME_DIR="../"; 
    

    And I include a file:

    include_once($TO_HOME_DIR."common/include_one.php");
    

    With if(!isset($TO_HOME_DIR)), it's not important how much you include a file into included file into included file into includ..... Only first file's -and main file's- $TO_HOME_DIR declaration is used.

    Second advantage of this approach is, if you change directory of file, you only need to change one line of code; $TO_HOME_DIR declaration. :)

提交回复
热议问题