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

时间:2015-01-15 04:10:44

标签: php fat-free-framework

我已经完成了Fat Free Framework文档中的示例,并且有一个例子我无法工作。它是以下内容:

$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();

我收到一条错误,指出找不到模板。该错误指向正在呈现template.htm文件的行,并且抱怨Preview-> render(即其超类,而不是Template-> render)。我甚至都没有在代码库中看到一个Preview类的文件。

有趣的是,如果我在View示例(下面)中使用相同的文件,它就可以正常工作。

$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();

但是,如果我要使用这个框架,我希望能够利用它的模板功能。

有这个框架经验的人是否知道可能出现什么问题?我从Github(https://github.com/bcosca/fatfree)下载了代码。

4 个答案:

答案 0 :(得分:1)

默认情况下,F3使用主文件所在的文件夹(启动框架实例的文件夹)。您可以通过为UI参数设置新路径来更改此行为。简而言之:

$f3 = \Base::instance();
$f3->set('UI', path_to_your_templates);

假设您具有以下结构:

- app
-- views
--- template.htm (your template)
- public
-- index.php (where your init the framework)
-- (template files are expected here by default)

public / index.php看起来像:

$f3 = \Base::instance();
$f3->set('UI',  __DIR__.'/../app/views/');
$f3->route('GET /',
function($f3) {
    echo  Template::instance()->render('template.htm');
}

希望有帮助。

答案 1 :(得分:0)

使用.html而不是.htm。是的,这真的很重要。

答案 2 :(得分:0)

我没有使用fat free framework的经验,但是有关如何调试此问题的一般指针。

显然,找不到文件的异常是由无内容框架内的一些代码抛出的。尝试使用XDebug

进行调试

答案 3 :(得分:0)

我使用Fat Free Framework 3.5.1版本遇到了这个问题

问题出现,因为框架OOB(至少在此版本中)与样本连接,以便在&u; /'中查找模板。 root fat free framework文件夹的子文件夹。

什么告诉我的?嗯... OOB config.ini有以下内容:

[globals]
DEBUG=3
UI=ui/

要轻松解决问题:

  1. 将文件' template.htm'在' ui /'子文件夹
  2. OR

    1. 重命名' ui /'在config.ini中将子文件夹添加到您喜欢的任何内容中并放入' template.htm'文件在该位置
    2. 提示:确保您指定的任何UI路径在/中结束,如果您需要指定多个路径,则可以使用|或者,或;分隔符(确保每个路径以/)结尾

相关问题