>[info]新建 `controllers/BaseController.php` 文件:
~~~
<?php
/**
* BaseController
*/
class BaseController
{
function __construct(argument)
{
# code...
}
}
~~~
>[info]新建 controllers/HomeController.php 文件:
~~~
<?php
/**
* HomeController
*/
class HomeController extends BaseController
{
public function home(){
echo "<h1>控制器创建成功!</h1>";
}
}
~~~
>[info]在config/routes.php中增加一条路由:
~~~
Macaw::get('', 'HomeController@home');
~~~
然后在浏览器直接打开:http://127.0.0.66/, 这个时候出现错误:
~~~
Fatal error: Class 'HomeController' not found in D:\WWW\my-framework\vendor\noahbuscher\macaw\Macaw.php on line 124
~~~
为什么没找到 HomeController 类?因为我们没有让他自动加载,修改 composer.json 为:
~~~
{
"require":{
"noahbuscher/macaw": "dev-master"
},
"autoload": {
"classmap": [
"app/controllers",
"app/models"
]
}
}
~~~
>[info]命令行运行
~~~
composer dump-autoload
~~~
![](https://box.kancloud.cn/62707ef29f3648bf4fd9779d5a848d27_436x76.png)
稍等片刻,刷新,你将看到以下内容:
![](https://box.kancloud.cn/d5aef5d1e4bc6e83bf07337b4d3df35f_474x179.png)
此时,命名空间使用成功!