我一直在尝试创建一个扩展UserFrosting's BaseController的自定义控制器,然后从index.php调用它的方法。看起来很简单,但到目前为止我非常不成功。我是UserFrosting的新手,因此我很可能错过了一些明显的东西。
控制器/LGController.php:
<?php
namespace UserFrosting;
class LGController extends 'UserFrosting'BaseController {
public function __construct($app){
$this->_app = $app;
}
public function lgRequestsList(){
$groups = array('Luke #1', 'Luke #2');
$this->_app->render('lg-request-list.twig', [
"groups" => $groups
]);
}
}
index . php:
...
use UserFrosting as UF;
$app->get('/lg/requests/?', function () use ($app) {
$controller = new UF'LGController($app);
return $controller->lgRequestsList();
});
...
错误:
[Wed Nov 09 15:25:40 2016] [warn] [client 160.34.126.11] mod_fcgid: stderr: Fatal error (1) in /home2/test/public_html/index.php on line 66: Class 'UserFrosting''LGController' not found, referer: http://xxx.co.uk/groups/g/1/auth
不要使用include
来包含新的控制器类。UserFrosting使用Composer自动加载文件。
一旦你安装了Composer,你所需要做的就是在你的userfrosting/
子目录下运行composer dump-autoload
,它会为你添加新的类