DIR 是一个魔术常量,如 PHP文档 所述。getcwd() 只是根据 PHP文档 当前的工作目录。
我的使用情况是:
// this is my index.php file
require_once __DIR__ . '/vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
$app->get('/{name}', function($name) use($app) {
return $app->sendFile(__DIR__ . '/web/source/index.php');
});
我不完全理解为什么我需要这两种机制,因为我应该只能使用相对路径。
然而,如果没有它,代码将失败。