I'm trying to use $this
inside a function of a route, when I'm doing this, it gives me the following error:
Using $this when not in object context
Here's the code:
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();
I have tried to implement it based on this.
Why it doesn't work to use $this
inside the function and how can I use $this
inside a function.