简体   繁体   English

Slim 框架 404 错误页面显示未找到错误

[英]Slim framework 404 error page showing not found error

I'm changing the default 404 error page on my slim framework v2.我正在更改我的超薄框架 v2 上的默认 404 错误页面。

This is the code I'm using:这是我正在使用的代码:

$app->notFound(function () use ($app) {
    $app->render('404.html');
});

However, I'm getting this error:但是,我收到此错误:

Message: View cannot render `404.html` because the template does not exist

I've the 404.html file in the same folder as my index.php which contains the Slim code.我的 404.html 文件与包含 Slim 代码的 index.php 位于同一文件夹中。 Also, just to check, I've copied the 404.html file in my slim folder also.另外,为了检查一下,我也将 404.html 文件复制到了我的 slim 文件夹中。 Still, I'm getting the same error.尽管如此,我还是遇到了同样的错误。 Is there something related to template?有没有与模板有关的东西?

[Solved] [解决了]

I solved this issue using this code:我使用以下代码解决了这个问题:

$app->notFound(function () use ($app) {
    $app->view->setTemplatesDirectory("Slim/");
    $app->render('404.html');
});

I just needed to set the Template Directory.我只需要设置模板目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM