Код: Выделить всё
FatalErrorException: Error: Call to a member function getUser() on a non-object
Код: Выделить всё
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
anonymous: true
stateless: true
http_basic:
realm: "REST Service Realm"
provider: fos_userbundle
access_control:
- { path: ^/users/me, role: IS_AUTHENTICATED_FULLY }
Я использую FOSRestBundle, а также FOSUserBundle (как вы можете видеть), и я не хотел ставить префикс, потому что это быть лишним:
Код: Выделить всё
// Routing.yml
rest :
type : rest
resource : "routing_rest.yml"
Код: Выделить всё
private function response($data, $status, $groups = array())
{
$currentUser = $this->container->get('security.context')->getToken()->getUser();
if (!$currentUser)
$groups = array("anon");
else
{
if ($currentUser->hasRole("ROLE_SUPER_ADMIN"))
array_push($groups, "admin");
else if ($currentUser->hasRole("ROLE_ADMIN"))
array_push($groups, "admin");
else if ($currentUser->hasRole("ROLE_USER"))
array_push($groups, "user");
}
return $this->view($data, $status)->setSerializationContext(SerializationContext::create()->setGroups($groups));
}
Подробнее здесь: https://stackoverflow.com/questions/264 ... rrent-user
Мобильная версия