缺少模板其余API CakePHP 3.x

问题描述 投票:2回答:1

[我用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->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']
  ]);
}
php cakephp cakephp-3.x
1个回答
0
投票

相同的错误,有人解决了吗?

© www.soinside.com 2019 - 2024. All rights reserved.