父母在错误的位置搜索



我正在尝试自定义在无脂肪框架顶部创建MVC文件夹结构。我有一个controllers文件夹,其中两个文件,base.phpindex.php。现在,我试图加载索引文件,例如:

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

,但我遇到了致命错误:

Fatal error: Class 'controllersBase' 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!";
    }
}

知道我做错了什么?

controllers文件夹应为您的AUTOLOAD文件夹的子文件夹。这样的东西:

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

和您的root index.php看起来像这样:

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

ps:示例中发生的事情是,将controllers文件夹声明为自动加载文件夹,base.phpindex.php被视为根名称空间的一部分。

最新更新