缺少RESTAPI CakePHP 3.x模板
我使用CakePHP 3.x构建了一个rest api,但是当我使用Postman 3.1.1进行测试时,出现了500个内部服务器错误: 找不到UsersController::token()的视图。) 在文件缺少RESTAPI CakePHP 3.x模板,php,cakephp,cakephp-3.x,Php,Cakephp,Cakephp 3.x,我使用CakePHP 3.x构建了一个rest api,但是当我使用Postman 3.1.1进行测试时,出现了500个内部服务器错误: 找不到UsersController::token()的视图。) 在文件routes.php中: Router::prefix('api', function ($routes) { $routes->extensions(['json']); $routes->resources('Users'); $routes->resou
routes.php
中:
Router::prefix('api', function ($routes) {
$routes->extensions(['json']);
$routes->resources('Users');
$routes->resources('Organizations');
$routes->resources('AccountRegistrations');
$routes->fallbacks('InflectedRoute');
});
在控制器中:
public function token() {
$user = $this->Auth->identify();
if (!$user) {
$message ='Invalid username or password';
}
$this->set([
'success' => true,
'data' => [
'token' => $token = \JWT::encode([
'id' => $user['id'],
'exp' => time() + 604800
],
Security::salt())
],
'_serialize' => ['success', 'data']
]);
}
您是否在URL中添加了
.json
扩展名?