【问题标题】:Slim framework 404 error page showing not found errorSlim 框架 404 错误页面显示未找到错误
【发布时间】:2019-12-08 12:44:16
【问题描述】:

我正在更改我的 slim 框架 v2 上的默认 404 错误页面。

这是我正在使用的代码:

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

但是,我收到了这个错误:

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

我的 404.html 文件与我的 index.php 位于同一文件夹中,其中包含 Slim 代码。另外,为了检查,我也将 404.html 文件复制到了我的 slim 文件夹中。不过,我遇到了同样的错误。有没有跟模板有关的东西?

【问题讨论】:

    标签: php slim


    【解决方案1】:

    [已解决]

    我用这段代码解决了这个问题:

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

    我只需要设置模板目录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      • 2012-09-15
      • 2012-07-12
      • 1970-01-01
      相关资源
      最近更新 更多