0
我試圖在路由的函數內使用$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
在函數內部。
- > ..'? – jmattheis
在所有我的路線功能 – JackTheKnife
爲您的問題添加示例 – jmattheis