我正在尝试$this
在路由的函数中使用,当我这样做时,它给了我以下错误:
Using $this when not in object context
这是代码:
function api($request, $response) {
$response->write('REST API v1');
$this->logger->addInfo("Something interesting happened");
return $response;
}
$app = new \Slim\App();
/** my routes here **/
$app->get('/', 'api');
$app->run();
我已经尝试基于this来实现它。
为什么$this
在函数内部使用不起作用以及如何在函数$this
内部使用。