/ Published in: Symfony
Expand |
Embed | Plain Text
Create a service class: 1) make a directory at bundle root: /Services 2) put a class there, e.g. <?php namespace Penny\HomeBundle\Services; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\SecurityContext; class MySecurity { //import security.context public function __construct() { } /** * * Check which entities user * can edit/delete * parameter: User entity */ public function belongsToUser($entity, $user_id) { //$s = new SecurityContext(new AuthenticationManagerInterface()); //$id = $s->getToken()->getUser()->getId(); $id = $this->get('security.context')->getToken()->getUser()->getId(); return $user_id === $entity->getUser()->getId(); } } ?> 3) change app/config/config.yml - add service class to it: parameters: items_per_page: 8 services: my_security: class: Penny\HomeBundle\Services\MySecurity paginated_query: class: Penny\HomeBundle\Services\PaginatedQuery arguments: [%items_per_page%, @security.context] 4) in action: //class name //method $this->get('paginated_query')->getResult($query, $page_num);
You need to login to post a comment.
