Khi tôi tiêm security.context phục vụ symfony2 của tôi (phần mở rộng cành lá) được lỗi sau xuất hiện:dùng Symfony2 truy cập từ dịch vụ mở rộng cành lá
Gọi để một hàm thành viên getUser() trên một tổ chức phi vật thể. ....
class GeninnoShareboardExtension extends \Twig_Extension {
public function __construct(ContainerInterface $container, SecurityContext $context) {
$this->doctrine = $container->get('doctrine');
$this->context = $context;
}
public function getUser() {
return $this->context->getToken()->getUser();
}
........
}
services.yml của tôi trông như thế này:
services:
geninno.twig.extension.dashboard:
class: Geninno\EDSBundle\Twig\Extension\GeninnoShareboardExtension
arguments:
container: "@service_container"
service: "@security.context"
tags:
- { name: twig.extension }
Một người dùng i s đăng nhập và thiết lập tường lửa của tôi là như thế này:
access_control:
- { path: ^/secured/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secured/create, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secured/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: [IS_AUTHENTICATED_FULLY, IS_AUTHENTICATED_REMEMBERED] }
Cảm ơn bạn nhưng nó không giải quyết vấn đề – Raymen