基本目录路径

MAGE_DIRS环境变量允许您指定自定义基本目录路径和基本URL的片段,Commerce应用程序使用这些路径构建各种文件的绝对路径或生成URL。

设置MAGE_DIRS

指定一个关联数组,其中键是来自\Magento\App\Filesystem\DirectoryList的常量,值分别为目录的绝对路径或其URL路径。

您可以通过以下任意方式设置MAGE_DIRS

  • 设置引导参数值

  • 使用自定义入口点脚本,如下所示:

    code language-php
    <?php
    /**
     * Copyright [first year code created] Adobe
     * All Rights Reserved.
     */
    
    use Magento\Framework\App\Bootstrap;
    use Magento\Framework\App\Filesystem\DirectoryList;
    use Magento\Framework\App\Http;
    
    require __DIR__ . '/app/bootstrap.php';
    $params = $_SERVER;
    $params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [
         DirectoryList::PUB => [DirectoryList::URL_PATH => ''],
         DirectoryList::MEDIA => [DirectoryList::PATH => '/mnt/nfs/media', DirectoryList::URL_PATH => ''],
         DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'],
         DirectoryList::UPLOAD => [DirectoryList::URL_PATH => '/mnt/nfs/media/upload'],
         DirectoryList::CACHE => [DirectoryList::PATH => '/mnt/nfs/cache'],
    ];
    $bootstrap = Bootstrap::create(BP, $params);
    /** @var Http $app */
    $app = $bootstrap->createApplication(Http::class);
    $bootstrap->run($app);
    

上述示例分别将[cache][media]目录的路径设置为/mnt/nfs/cache/mnt/nfs/media

recommendation-more-help
386822bd-e32c-40a8-81c2-ed90ad1e198c