I wan’t displaying all users
in my admin page
.
I don’t found and i don’t know the function symfony
to return all users
in angular
. Would you know the code please?
I use a db, with mysql and phpmyadmin
I know the problem comes from my symfony function. I would like the function that returns all the user listed backoffice
My function in UserController.php :
/**
* @RestGet("/allUsers")
*/
public function getAllUsers()
{
// TODO: récupérer tout les utilisateurs de la base de donnée.
$user = $this->get('security.token_storage')->getDoctrine()->getUser();;
return new Response($user);
}
My userService.ts :
getAllUsers() {
return this.api.get('api/user/allUsers');
}
I use Angular 7
and Symfony 4
I return the current user whit that function in my UserController.php
public function getUser()
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$response = $this->serializer->serialize($user, 'json', SerializationContext::create()->setGroups(array('user.get')));
return new Response($response);
}
2
Answers
you didn’t provide your app component but i assume you have not made a method that gets your data from the service. ill share one of my Methods for getting a data from a service.
If you use an Http request (you use Rest API) so :
this is how your service should look :
Change the Method name and Object according to your names.
And here is the Component Method :
Change it according to your names.
Basically you need to subscribe to your method -> think of it like a viewer subscribing to a YouTube channel. and the keeps looking for new videos.
Simple API
call that api Using Angular HTTPClient