Symfony 4-API平台-JWT-自定义操作和控制器

时间:2018-07-03 11:49:21

标签: http-status-code-404 symfony4 api-platform.com lexikjwtauthbundle

我正在使用Symfony 4.1进行项目-api平台-jwt
我在实体中创建了一个自定义操作

// App\Entity
/**
 * @ApiResource(
 *  itemOperations={
 *    "get",
 *    "put",
 *    "delete",
 *    "request"={
 *      "method"="POST",
 *      "path"="/event/request",
 *      "controller"=ReservationController::class
 *    }
 *  }
 * )
 * @ORM\Entity(repositoryClass="App\Repository\EventRepository")
 */

我在Approprite控制器中创建了方法

public function __invoke(Event $data): ?Event
{
    $eventType = $this->getDoctrine()->getRepository(EventType::class)->findRequestType();
    $user = $this->getDoctrine()->getRepository(User::class)->find(1);
    $data->setEventType($eventType);
    $data->setUser($user);
    return $data;
}

在集成JWT之前,它运行得很好,但是现在当我尝试访问资源时,我得到了这个

2018-07-03T11:19:44+00:00 [info] Matched route "api_events_request_item".
2018-07-03T11:19:44+00:00 [debug] Checking for guard authentication credentials.
2018-07-03T11:19:44+00:00 [debug] Calling getCredentials() on guard configurator.
2018-07-03T11:19:44+00:00 [debug] Passing guard token information to the GuardAuthenticationProvider
2018-07-03T11:19:44+00:00 [debug] SELECT t0.id AS id_1, t0.email AS email_2, t0.password AS password_3, t0.is_active AS is_active_4, t0.role_id AS role_id_5 FROM user t0 WHERE t0.email = ? LIMIT 1
2018-07-03T11:19:44+00:00 [info] User Deprecated: Calling Symfony\Component\Security\Core\User\UserChecker::checkPreAuth with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.
2018-07-03T11:19:44+00:00 [info] User Deprecated: Calling Symfony\Component\Security\Core\User\UserChecker::checkPostAuth with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.
2018-07-03T11:19:44+00:00 [info] Guard authentication successful!
2018-07-03T11:19:44+00:00 [debug] Guard authenticator set no success response: request continues.
2018-07-03T11:19:44+00:00 [debug] Remember me skipped: it is not configured for the firewall.
2018-07-03T11:19:44+00:00 [error] Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "Not Found" at /Users/simonackermann/Sites/courses/symfony/champeryNb/vendor/api-platform/core/src/EventListener/ReadListener.php line 103
[Tue Jul  3 13:19:44 2018] 127.0.0.1:56389 [404]: /api/event/request

这是我通过debug:router命令得到的结果

default                          ANY      ANY      ANY    /
test                             ANY      ANY      ANY    /test
images                           ANY      ANY      ANY    /images/{name}
api_entrypoint                   ANY      ANY      ANY    /api/{index}.{_format}
api_doc                          ANY      ANY      ANY    /api/docs.{_format}
api_jsonld_context               ANY      ANY      ANY    /api/contexts/{shortName}.{_format}
api_events_get_collection        GET      ANY      ANY    /api/events.{_format}
api_events_post_collection       POST     ANY      ANY    /api/events.{_format}
api_events_get_item              GET      ANY      ANY    /api/events/{id}.{_format}
api_events_put_item              PUT      ANY      ANY    /api/events/{id}.{_format}
api_events_delete_item           DELETE   ANY      ANY    /api/events/{id}.{_format}
api_events_request_item          POST     ANY      ANY    /api/event/request
api_event_types_get_collection   GET      ANY      ANY    /api/event_types.{_format}
api_event_types_get_item         GET      ANY      ANY    /api/event_types/{id}.{_format}
api_places_get_collection        GET      ANY      ANY    /api/places.{_format}
api_places_post_collection       POST     ANY      ANY    /api/places.{_format}
api_places_get_item              GET      ANY      ANY    /api/places/{id}.{_format}
api_places_delete_item           DELETE   ANY      ANY    /api/places/{id}.{_format}
api_places_put_item              PUT      ANY      ANY    /api/places/{id}.{_format}
api_users_get_collection         GET      ANY      ANY    /api/users.{_format}
api_users_post_collection        POST     ANY      ANY    /api/users.{_format}
api_users_get_item               GET      ANY      ANY    /api/users/{id}.{_format}
api_users_delete_item            DELETE   ANY      ANY    /api/users/{id}.{_format}
api_users_put_item               PUT      ANY      ANY    /api/users/{id}.{_format}
api_users_name_item              GET      ANY      ANY    /api/user/{email}
_twig_error_test                 ANY      ANY      ANY    /_error/{code}.{_format}
api_login_check                  ANY      ANY      ANY    /api/login_check

有什么想法吗?
预先感谢

0 个答案:

没有答案