0

我正在尝试在无脂肪框架之上自定义创建 MVC 文件夹结构。我有一个controllers包含两个文件的文件夹,base.php并且index.php. 现在我正在尝试加载索引文件,例如:

$f3->route('GET /','Index->index');

但我收到一个致命错误:

Fatal error: Class 'controllers\Base' not found

base.php 的代码:

<?php
namespace controllers;
class Base extends \Prefab {
    protected $f3;

    public function __construct() {
        $this->f3 = \Base::instance();
    }
}

index.php 的代码

<?php
namespace controllers;
class Index extends Base {

    public function __construct() {
        parent::__construct();
    }

    public function index($f3, $params) {
        echo "Hello World!";
    }
}

知道我做错了什么吗?

4

1 回答 1

0

controllers文件夹应该是您的文件夹的子AUTOLOAD文件夹。像这样的东西:

- autoload
 |- controllers
   |- base.php
   |- index.php
- lib
 |- base.php
- index.php

你的根 index.php 看起来像这样:

$f3=require('lib/base.php');
$f3->set('AUTOLOAD','autoload/');
$f3->route('GET /','controllers\Index->index');

PS:您的示例中发生的情况是该controllers文件夹被声明为自动加载文件夹,base.php并被index.php视为根命名空间的一部分。

于 2014-03-08T10:13:46.607 回答