模板未找到错误 - 无脂肪框架

I have worked through the examples in the documentation for the Fat Free Framework, and there is one example that I cannot get to work. It is the following:

$f3=require('lib/base.php');
$f3->route('GET /',
    function($f3) {
        $f3->set('name','world');
        $template=new Template;
        echo $template->render('template.htm');
        // Above lines can be written as:
        // echo Template::instance()->render('template.htm');
    }
);
$f3->run();

I receive an error that the Template is not found. The error points to the line in which the template.htm file is being rendered and complains of Preview->render (i.e. its superclass, instead of Template->render). I don't even see a file for a Preview class in the codebase.

Interestingly, if I use the same file for the View example (below), it works just fine.

$f3=require('lib/base.php');
$f3->route('GET /',
    function($f3) {
        $f3->set('name','world');
        $view=new View;
        echo $view->render('template.htm');
        // Previous two lines can be shortened to:
        // echo View::instance()->render('template.htm');
    }
);
$f3->run();

However, if I am going to use this framework, I would like to be able to utilize its templating feature as well.

Does anyone with experience with this framework have any idea what could be the problem? I downloaded the code from Github (https://github.com/bcosca/fatfree).

Use .html instead of .htm. Yep, it really matters.

I have no experience using fat free framework, but a general pointer on how to debug this issue.

Apparently the file not found exception is being thrown by some code inside fat free framework. Try debugging that using XDebug

I ran across this issue with version Fat Free Framework 3.5.1

The issue appears since the framework OOB (in at least this version) is wired with a sample such that the templates are looked for in the 'ui/' subfolder of the root fat free framework folder.

What tells me that? Well... the OOB config.ini has the following contents:

[globals]
DEBUG=3
UI=ui/

To easily solve the problem either:

  1. Put the file 'template.htm' in the 'ui/' subfolder

OR

  1. Rename the 'ui/' subfolder to whatever you like in the config.ini and put the 'template.htm' file in that location

TIP: Make sure whatever UI path you specify ends in a / and if you need to specify multiple paths you can use the | or , or ; separators (making sure each path ends in a /)