Fat Free Framework 入门错误

发布于 2024-12-14 04:55:29 字数 326 浏览 4 评论 0原文

我已经使用 无脂肪框架 创建了第一个 .php 文件,但它不起作用

文件内容:

<?php
  require_once("../fatfree/lib/base.php");
  F3::route('GET /','home');
    function home() 
    {
        echo 'Hello, world!';
    }
  F3::run();
?>

I'我收到 404 错误

I've create a first .php file with fat free framework but it is not working

Contents of file:

<?php
  require_once("../fatfree/lib/base.php");
  F3::route('GET /','home');
    function home() 
    {
        echo 'Hello, world!';
    }
  F3::run();
?>

I'm getting a 404 error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总以为 2024-12-21 04:55:29

路由引擎不能调用这样的松散函数。您应该使您的函数成为这样的类的方法:

<?php
  require_once("../fatfree/lib/base.php");
  F3::route('GET /','foo->home');
  class foo{
    public function home() 
    {
        echo 'Hello, world!';
    }
  }
  F3::run();
?>

或者将您的 home 函数变成像这样的匿名函数:

<?php
  require_once("../fatfree/lib/base.php");
  F3::route('GET /',function() {
        echo 'Hello, world!';
    }
  );
  F3::run();
?>

The routing engine can't call loose functions like that. You should either make your function a method of a class like this:

<?php
  require_once("../fatfree/lib/base.php");
  F3::route('GET /','foo->home');
  class foo{
    public function home() 
    {
        echo 'Hello, world!';
    }
  }
  F3::run();
?>

OR turn your home function into an anonimous function like this:

<?php
  require_once("../fatfree/lib/base.php");
  F3::route('GET /',function() {
        echo 'Hello, world!';
    }
  );
  F3::run();
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文