Fat-free php 无效路线

Fat-free php invalid route

我目前遇到 fat-free 框架的路由问题。在环顾四周并阅读文档后,尽管这似乎是一个简单的问题,但我到目前为止仍无法解决它。

我从根目录使用 f3 的标准路由格式:

$f3->route(array('GET /', 'GET /index.php'), function($f3) {
    include 'header.html';
    include 'Home/index.html';
    include 'footer.html';
});

//search
$f3->route('GET /Browse', function() {
    include 'Browse/index.html';
});

这些路由均按预期正常工作。当我在 xammp 上输入 localhost 时,两个 return 页面都被概述了。两者都有一个文件结构:

-Root
-index.php
-header.html
-footer.html
--Browse
---index.html

定义新路由后,我不希望有一个包含 index.html 文件的文件夹,而是通过回显 html.

来响应
$f3->route('GET /Latest',
    function() {
        include 'submit/index.html';
        echo 'This is our home page.';
    }
);

当我使用上面的代码并转到 localhost/Latest 时,我看到:

Error 404 : Not found

我的问题是如何允许直接来自 PHP 的响应而无需后续文件夹和 index.html 文件。

谢谢和问候:)

您可能正在寻找框架 template engine

有多种方法可以构建代码,但这里有一个简单的基本示例:

// index.php

$f3->UI='templates/';

$f3->route('GET /home',function($f3){
    $f3->main='home.html';
    $f3->title='Homepage';
    $tpl=Template::instance();
    echo $tpl->render('layout.html');
});

$f3->route('GET /contact',function($f3){
    $f3->main='contact.html';
    $f3->title='Contact us';
    $f3->address='5578 Grant Street Woodbridge, VA 22191';
    $tpl=Template::instance();
    echo $tpl->render('layout.html');
});
<!-- templates/layout.html -->
<!DOCTYPE html>
<title>{{ @title }}</title>

<body>
  <include href="header.html"/>
  <main>
    <include href="{{ @main }}"/>
  </main>
  <include href="footer.html"/>
</body>
<!-- templates/home.html -->
<h1>Hey hey! Welcome home!</h1>
<!-- templates/contact.html -->
<h1>Our address</h1>
<p>{{ @address }}</p>

至于 404 错误,请确保您的 .htaccess 文件配置正确,尤其是 RewriteBase 指令。如果不是,则 / 以外的每个 URI 都会抛出 404。有关设置的更多详细信息,请参阅 here