VPS上的Slim 3无法找到模板目录
今天,我在我的Web服务器(VPS)上配置了我的瘦身应用程序。 我构建了项目,以便我的public_html包含Slim的索引文件和.htaccess文件,并且后台文件位于(/../public_html)之前的文件夹中(我想这是自“公共”文件的正确配置。应用程序是在“公共”文件夹 可悲的是我错了,如果我浏览到我的网站,我得到一个苗条的错误说的模板:VPS上的Slim 3无法找到模板目录
The "templates" directory does not exist ("/var/www/mywebsitefolder/public_html/templates").
这是奇怪的,因为我说我的isettings.php文件定位模板文件夹内的一个BEFORE 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
有什么建议吗?我遵循正确的逻辑?
我是新来的苗条,所以我很抱歉,如果这个答案是天真的或做错的方式。
我有同样的问题 - 我创建的应用程序在本地工作(使用php -S localhost:8080 -t public public/index.php
)。当我将它移动到VPS时,它停止工作,因为它正在寻找public
目录中的模板目录。
我固定它通过初始化的树枝像这样(在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;
};
本来嫩枝正在以字符串"templates"
而不是对template_path
呼叫设置初始化。
令人惊叹!完全没有想到这一点,谢谢,我想我会标记这是正确的,我实际上已经通过将templates目录移动到public来解决此问题,并且一切正常,但是您的方法更“干净”。 – K3nzie
我最近也碰到过这个。你使用的是什么模板引擎? –
@ChrisHerbert Twig – K3nzie