VPS 上托管的 Slim 3 找不到模板目录

Slim 3 hosted on VPS can't find templates directory

今天我在我的网络服务器上配置了我的 slim 应用程序 (VPS)。 我构建了项目,使我的 public_html 包含 Slim 的索引文件和 .htaccess 文件,背景文件在 (/../public_html) 之前的文件夹中(我认为这是正确的配置,因为应用程序的 "public" 文件位于 "public" 文件夹中。 可悲的是我错了,如果我浏览我的网站,我会收到一个小错误说模板:

The "templates" directory does not exist ("/var/www/mywebsitefolder/public_html/templates").

这很奇怪,因为我说我的 isettings.php 文件将模板文件夹定位在 public_html 之前的文件夹中,如我的文件所述:

// Renderer settings
    'renderer' => [
        'template_path' => __DIR__ . '/../templates/',
    ],

所以它应该查看 /../templates,但它没有发生,这也是我在 public_html 中配置我的 .htaccess 的方式,其中 index.php 是:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

还有我的文件夹结构(也许能帮上忙)

- **my website apache folder**
 - Controllers
 - Models
 - src
 - templates
 - vendor
 - public_html
   - css
   - imgs
   - js
   - index.php 
   - .htaccess

有什么建议吗?我遵循了正确的逻辑?

我是 Slim 的新手,所以如果这个回答太幼稚或者做错了,我深表歉意。

我遇到了同样的问题 - 我创建的应用程序在本地运行(使用 php -S localhost:8080 -t public public/index.php)。当我将它移动到 VPS 时,它停止工作,因为它正在寻找 public 目录中的模板目录。

我通过像这样初始化 Twig 来修复它(在 src/dependencies.php 中):

// Register component on container
$container['view'] = function ($container) {

    $view = new \Slim\Views\Twig(
        $container->get('settings')['renderer']['template_path']
    );

    // Removed more Twig setup code

    return $view;
};

最初 Twig 是用字符串 "templates" 初始化的,而不是调用 template_path 设置。