我正在尝试自定义在无脂肪框架顶部创建MVC文件夹结构。我有一个controllers
文件夹,其中两个文件,base.php
和index.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.php
和index.php
被视为根名称空间的一部分。