I am now doing some experiments on my own, for example, to invoke my cousin's path, I ask how to use the path in a real project?
如果C:\AppServ\www\YB-PHP\PathDemo\China\ShanDong\LinYi\03.php调用C:\AppServ\www\YB-PHP\PathDemo\China\JiangSu\NanJing\NanJingEcho.php就得写:include('../../JiangSu/NanJing/NanJingEcho.php');
It's always easy to make a few mistakes. /"Every time I count this, I get so confused, how to write a simple point?"
I asked, and others told me to define the server with constants:
define('BASEPATH', 'C:\AppServ\www\YB-PHP\PathDemo\China\');include(BASEPATH . 'JiangSu/NanJing/NanJingEcho.php');
There seems to be a question of what permissions, I would like to ask, when the real project, how to use the parent path, cousin Path, the local path? To ensure that you change the server, the project can also be used?
Reply content:
I am now doing some experiments on my own, for example, to invoke my cousin's path, I ask how to use the path in a real project?
如果C:\AppServ\www\YB-PHP\PathDemo\China\ShanDong\LinYi\03.php调用C:\AppServ\www\YB-PHP\PathDemo\China\JiangSu\NanJing\NanJingEcho.php就得写:include('../../JiangSu/NanJing/NanJingEcho.php');
It's always easy to make a few mistakes. /"Every time I count this, I get so confused, how to write a simple point?"
I asked, and others told me to define the server with constants:
define('BASEPATH', 'C:\AppServ\www\YB-PHP\PathDemo\China\');include(BASEPATH . 'JiangSu/NanJing/NanJingEcho.php');
There seems to be a question of what permissions, I would like to ask, when the real project, how to use the parent path, cousin Path, the local path? To ensure that you change the server, the project can also be used?
Obviously 2 is a better solution, there is no permission problem you are considering: if there is a problem with permissions, then you use the. /.. /In the form of this problem will also occur .
Scenario 2 is also commonly used in a way that is actually more complex, such as:
defined('BASE_PATH') || define('BASE_PATH', __DIR__);defined('UPLOAD_BASE_URL') || define('UPLOAD_BASE_URL', '/uploads');defined('UPLOAD_PATH') || define('UPLOAD_PATH', BASE_PATH . UPLOAD_BASE_URL);//等等
When you refer to a file, you can see what is convenient, such as
require_once(BASE_PATH . '/app/functions.php');//或者require_once(__DIR__ . '/functions.php');
It's all OK.
To learn how to use __file__, __dir__, this is the best way to write the path directly, such as c:/workspace/project/app/functions.php, then what if the project is deployed to Linux?
So, take full account of the migration.
Hope to be helpful.
Cross-project invocation? is generally open an interface? Or two of projects need this data? Then open an API project alone.
Or is it a project where you want to invoke the database-driven class library? Then put this class library to find a Lib directory unified to include?
Generally this step by step to solve the problem, with the actual situation to analyze and solve the problem