简体   繁体   中英

Include php files the correct way

/* index.php */
require_once('region.php');
require_once('es.php');
  • index.php includes region.php -region-related info (also sets $regionLang = 'es'; ) and es.php -mostly Spanish translations. Second file needed if language is Spanish 'es' or it would be a different file eg 'en-us.php'
  • would you include es.php inside region.php and why? Also how?
    • region.php is essential, es.php is important but scripts will run withot translations
    • whatever language is used in region.php, the corresponding translation file will be required
    • require() or include() in case of es.php ?
/* index.php */
require_once('region.php');
/* region.php */
require_once('es.php');

I would include es.php into region.php

Because, region.php decide my language whether it is spanish or not. If it is not my language, i can change the language file

We suppose in region.php;

//region.php    
    if(myRegion()=="Turkey"){
      require_once('turkish.php');
    }else if(myRegion()=="Spania"){
      require_once('es.php');
    }

so we avoid unnecessary file loads

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