【发布时间】:2017-08-23 18:59:11
【问题描述】:
我试图在路由函数中使用$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。
【问题讨论】:
-
你在哪里使用
$this->..? -
在我所有的路由函数中
-
为您的问题添加示例
-
@jmattheis OP 更新了示例路线